增强型for循环对二维数组的输出(test8.java)

  由于笔者原因,这部分知识,尚不能整理出代码,笔者会好好学习增强型for循环中迭代起的相关知识,在笔者有能力,书写好这段代码后,将对本篇文章,进行二次修改,也同时欢迎大家与笔者交流,共同学习,共同进步。

  

  目前的话只能给出下面的参考代码,具体实现,会通过二次编辑进行补充说明。

 1 //导入输入所需要的包
 2 import java.util.Scanner;
 3 
 4 public class test8
 5 {
 6     public static void main(String [] arys)
 7     {
 8         //创建一个5行5列的二维数组
 9         int [][] arrs = new int [5][5];
10 
11         for(int i=0 ; i<5 ; i++)
12         {
13             for(int j=0 ; j<5 ; j++)
14             {
15                 arrs[i][j] = (i+1)*10+j;
16             }
17         }
18 
19         //增强型for循环输出
20         for(int [] arr : arrs)
21         {
22             for(int num : arr)
23             {
24                 System.out.print(num+"\t");
25             }
26             System.out.println();
27         }
28     }
29 }

猜你喜欢

转载自www.cnblogs.com/zglbt/p/8934988.html