第七天打卡
package demo01; public class classMXS7191 { public static void main(String[] args) { int[][] ar1=new int[11][11]; ar1[1][2] = 1; ar1[2][3]= 2; for (int[] ints:ar1){ for (int anInt : ints){ System.out.print(anInt+"\t"); } System.out.println(); } System.out.println("-----------------"); int sum =0; for (int i=0;i<11;i++){ for (int j=0;j<11;j++){ if (ar1[i][j]!=0){ sum++; } } } System.out.println(sum); System.out.println("-----------------"); int[][] aa = new int[sum+1][3]; aa[0][0] =11; aa[0][1]= 11; aa[0][2]= sum; int count = 0; for (int i=0;i<ar1.length;i++){ for (int j=0;j<ar1[i].length;j++){ if (ar1[i][j]!=0){ count++; aa[count][0]=i; aa[count][1]=j; aa[count][2]=ar1[i][j]; } } } for (int i=0;i<aa.length;i++){ System.out.println(aa[i][0]+"\t"+aa[i][1]+"\t" +aa[i][2]+"\t"); } System.out.println("-----------------"); int[][] tt = new int[aa[0][0]][aa[0][1]]; for (int i =1;i<aa.length;i++){ tt[aa[i][0]][aa[i][1]] = aa[i][2]; } for (int[] ints:tt){ for (int anInt : ints){ System.out.print(anInt+"\t"); } System.out.println(); } } }
今天 java部分学到60 面向对象