题目如图所示,横线上应该填什么?
java 杨辉三角
答案:3 悬赏:60
解决时间 2021-04-23 04:04
- 提问者网友:幽瑟玉琼情殇
- 2021-04-22 05:00
最佳答案
- 二级知识专家网友:浪者不回头
- 2021-04-22 05:26
f(m-1,n)+f(m-1,n-1)
全部回答
- 1楼网友:有钳、任性
- 2021-04-22 06:35
(n=((n>=m/2)?(m-n):n))*m
非要写在一起,要是用if来直接判断要简单些,但代码要多些。。这句话我没测试过,你测试下对不对,我这没设备可以测试。
- 2楼网友:24K纯糖
- 2021-04-22 06:19
package zhidao;
public class testyanghui
{
private static int[][] array = null;
public static void main ( string[] args )
{
array = testyanghui.getyanghui (4);
for( int i = 0; i < array.length; i++ )
{
for( int j = i; j < array.length; j++ )
{
system.out.print (" ");
}
for( int j = 0; j <= i; j++ )
{
system.out.print (array[i][j] + " ");
}
system.out.println ();
}
system.out.println ("====================\n以上就是杨辉三角");
}
private static int[][] getyanghui ( int row )
{
int[][] array = new int[row][row];
array[0][0] = 1;
for( int i = 1; i < row; i++ )
{
for( int j = 0; j < row; j++ )
{
// 第一列和最后一列
if(0 == j || ( row - 1 ) == j)
{
array[i][j] = 1;
}
// 其他行
else
{
array[i][j] = array[i - 1][j] + array[i - 1][j - 1];
}
}
}
return array;
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯