/*多行注释的快捷键:Ctrl+shift+/
快速格式化代码快捷键:Ctrl+shift+f
自动导入一个包:Ctrl+shift+o
*/
package test_1;
public class Day_2 {
public static void main(String args[]) {
//一个九九乘法表的实现
int c = 0;
for (int a = 1; a <= 9; a++) {
for (int b = 1; b <= a; b++) {
c = a * b;
System.out.printf("%d*%d=%d ",b,a,c);
}
System.out.println();
}
System.out.println("-------------------我是华丽的分割线--------------------------");
// 遍历数组的方法
// 方法1:
int arr[] = new int[3];
for (int a = 0; a < arr.length; a++) {
System.out.println(arr[a]);
}
System.out.println("-------------------我是华丽的分割线--------------------------");
//方法2:
for (int a : arr) {
System.out.println(a);
}
System.out.println("-------------------我是华丽的分割线--------------------------");
//二维数组的遍历
int arr2[][]=new int[][]{
{1,2,3},
{4,5,6},
{7,8,9}
};
for(int i=0;i<arr2.length;i++){
for(int j=0;j<arr2[0].length;j++){
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
}
}
相关文章:
- swift-for循环遍历,遍历字典,循环生成数组 2021-05-18
- js中的for-of循环遍历数组 2021-09-29
- php中数组的遍历之for循环 2021-08-01
- 二维数组遍历的方式(for普通循环遍历、foreach循环遍历、toString方式遍历) 2021-11-10
- 使用for循环遍历文件、使用while循环遍历文件 2021-06-21
- php数组的循环遍历 2022-12-23
- swift基本用法-for循环遍历,遍历字典,循环生成数组 2022-12-23
- php for循环遍历索引数组 2022-12-23