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(); } } }