码迷,mamicode.com
首页 > 编程语言 > 详细

遍历数组

时间:2018-11-02 00:08:10      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:pre   ++   二维   遍历数组   out   循环   []   int   rgs   

遍历数组:就是获取数组中的每个元素

使用for循环实现

遍历二维数组

1,双for循环

2,双foreach循环

//双for循环
public class source {
    public static void main(String[] args) {
        int a[][]=new int[][]{{1},{2,3},{3,4,5}};
             for(int i=0;i<a.length;i++){
                   for(int j=0;j<a[i].length;i++){
                             System.out.print(a[i][j]);
                  }
                        System.out.println();
           }
                   for(int k[]:a){//将所有行元素提取出来
                           for(int c:k ){//将行中所有列元素提取出来
                              System.out.println(c);
                                   }
                                      System.out.println();    
                            }
                  }
    
        }

 

遍历数组

标签:pre   ++   二维   遍历数组   out   循环   []   int   rgs   

原文地址:https://www.cnblogs.com/mld1040871703/p/9893063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!