首页 > 编程语言 > 详细

java 第5章 数组

时间:2016-06-25 09:37:36      阅读:260      评论:0      收藏:0      [点我收藏+]

2016-06-25

1、一维数组

package test;

public class JudgePrime {
    public static void main(String[] args){
        int [] ages = {12,18,9,33,45,60};
        int i = 1;
        for (int age:ages){
            System.out.println("数组中第"+i+"个元素是 "+age);
            i++;
        }
    }

}

技术分享

2、二维数组

package test;

public class JudgePrime {
    public static void main(String[] args){
        String [][] name ={{"ZhaoYi","QianEr","SunSan"},{"LiSi","ZhouWu","WuLiu"}};
        for (int i = 0;i<2;i++){
            for(int j = 0;j < 3; j++){
                System.out.println(name[i][j]);
            }
        }
    }
}

技术分享

每10个数为一组,打印出前100的数

package test;

public class PrintNum {
    public static void main(String[] args){
        int num[][] = new int[10][10];
        int count = 0;
        for(int i = 0; i< 10; i++){
            for(int j = 0; j< 10; j++) {
                num[i][j] = count++;
                System.out.printf("%02d ", num[i][j]);
            }
            System.out.println();
        }
    }

}

技术分享

 

java 第5章 数组

原文:http://www.cnblogs.com/cenliang/p/5615800.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!