一维
int[] a=new int[12];
int[] a={11,22,33,44,55};
int[] a=new int{11,22,33,44,55};
int[] a;
a=new int[12];
例如1:
package www; public class ww4 { public static void main(String[] args) { int[] a=new int[5]; int[] i= {11,22,33,44,55}; int[] j; j= new int[5]; for (int b = 0; b < a.length; b++) { for (int c = 0; c< i.length; c++) { for (int d = 0; d < j.length; d++) { System.out.println(a[b]); System.out.println(i[c]); System.out.println(j[d]); } } } } }
二(三)维
二: int[][] a={{11,22,33,44},{55,66,77,88,9}};
三: int[][][] a={{11,22,33},{44,55,66},{77,88,99}};
例如2:
package www; public class ww4 { public static void main(String[] args) { int[][] a= {{11,22,33},{44,55,66}}; for (int i = 0; i < a.length; i++) { for (int j = 0; j< a.length; j++) { System.out.println(a[i][j]); } } int[][] b= {{11,22,33},{44,55,66},{77,88,99}}; for (int i = 0; i < b.length; i++) { for (int j = 0; j< b.length; j++) { System.out.println(b[i][j]); } } } }
先假设再比较
例如3:
package 豪富; public class ss { public static void main(String[] args) throws Exception { int[][] a= {{11,22,33,43},{44,55,66,45},{77,88,99,87}}; int min=a[0][0]; int max=a[0][0]; for (int i = 0; i < 3; i++) { for (int j = 0; j <4; j++) { if (a[i][j]>max) { max=a[i][j]; System.out.println("最大数在第"+i+"行"); if(a[i][j]<min) { min=a[i][j]; } } } } System.out.println(min); System.out.println(max); } }
*1:*直角三角形
package 豪富; public class ss { public static void main(String[] args) throws Exception { for (int i = 0; i <=6; i++) { for (int j = 0; j <i-1; j++) { System.out.print(" *"); } System.out.println(""); } } }
这章总体有点难,所有的知识都需要慢慢钻研,不能心急,更不能虚度时光,一步一个脚印,踏踏实实学好基础知识,以后才能运用好。加油!努力就会有成果!