java二维数组定义初始化-杨辉三角
2024-10-19 12:43:29
public class Array2Demo2_3 { public static void main(String[] args) { //定义初始化
int[][] arr = new int[3][];//定义高维数组
arr[0] = new int[2];//高位数组下定义低维数组
arr[1] = new int[3];
arr[2] = new int[4]; arr[0][0] = 1;//给低维数组初始化
arr[0][1] = 2;
arr[1][0] = 1;
arr[1][1] = 2;
arr[1][2] = 3;
arr[2][0] = 1;
arr[2][1] = 2;
arr[2][2] = 3;
arr[2][3] = 4; for(int i = 0;i<arr.length;i++) {
for(int j = 0;j<arr[i].length;j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
//-------------------------杨辉三角----------------------------
int row = 8;
int[][] arr1 = new int[row][row];
for(int i = 0;i<row;i++) {
for(int j = 0;j<=i;j++) {
if(j == 0||j == i) {
arr1[i][j] =1;
}else {
arr1[i][j] = arr1[i-1][j-1]+arr1[i-1][j];
}
}
} for(int i = 0;i<row;i++) {
for(int j = 0;j<=i;j++) {
System.out.print(arr1[i][j]+" ");
}
System.out.println();
}
} }
最新文章
- KTV项目 SQL数据库的应用 结合C#应用窗体
- HtmlAgilityPack使用
- [翻译]:SQL死锁-锁与事务级别
- 添加网页ico
- jquery获得option的值和对option进行操作 作者: 字体:[增加 减小] 类型:转载 时间:2013-12-13 我要评论
- c++ 对象内存布局详解
- CMD删除Mysql 服务
- 对XXX(数字)安全卫士实在是忍无可忍了,为什么一定要像日本鬼子强奸妇女一样强奸我们这些弱小者
- 一个load飙高的过程分析,非常有价值(转)
- android判断网络的类型
- Windows 上连接本地 Linux虚拟机上的 mysql 数据库
- .net 支付宝接口小小误区
- 安装并运行Hello World
- mac os使用迁移助手之后运行php报:dyld相关错误,错误排错流程分析
- Javascript 实现[网红] 时间轮盘
- Intel 8086_通用寄存器|段寄存器
- 一个简单例子理解C#的协变和逆变
- MFC修改窗口无标题和标题信息,修改执执行文件图标
- Delphi中使用OLE方法操作Excel
- jacoco生成覆盖率