Simple array, two-bit array
1 PackageCom.lovo;2 3 ImportJava.util.Scanner;4 5 /**6 * Two-dimensional array7 * 8 * @authorWang Qiwen9 * Ten */ One A Public classD2 { - Public Static voidMain (string[] args) { -Scanner sc =NewScanner (system.in); the -String[] names = {"Zhao da", "Money Two", "Magozo", "John Doe", "Friday" }; -String[] Course = {"Language", "maths", "English" }; - Double[] scores =New Double[5] [3]; + - for(inti = 0; i < scores.length; ++i) { +System.out.println ("Please enter" + Names[i] + "score:"); A for(intj = 0; J < Scores[i].length; ++j) { atSystem.out.print ("\ T" + course[j] + ":"); -SCORES[I][J] =sc.nextdouble (); - } - } - - DoubleChsum = 0; in DoubleMasum = 0; - DoubleEnsum = 0; to + for(inti = 0; i < scores.length; ++i) { - Doublesum = 0; the for(intj = 0; J < Scores[i].length; ++j) { *Sum + =Scores[i][j]; $ if(j = = 0) {Panax NotoginsengChsum + =Scores[i][j]; - } the if(J = = 1) { +Masum + =Scores[i][j]; A } the if(J = = 2) { +Ensum + =Scores[i][j]; - } $ } $System.out.printf (average of "%s:%.2f\n"), names[i], sum -/scores[i].length); - } the -System.out.printf ("Average of Language:%.2f\n", Chsum/names.length);WuyiSystem.out.printf ("The average of mathematics is divided into:%.2f\n", Masum/names.length); theSystem.out.printf ("Average English is divided into:%.2f\n", Ensum/names.length); - Wu sc.close (); - } About}
Yang Hui Triangle
1 PackageCom.lovo;2 3 /**4 * Yang Hui triangle5 * 6 * @authorWang Qiwen7 * 8 */9 Public classD3 {Ten Public Static voidMain (string[] args) { One int[] h =New int[10][]; A - for(inti = 0; i < h.length; ++i) { -H[i] =New int[i + 1]; the for(intj = 0; J < H[i].length; ++j) { - if(j = = 0 | | j = =i) { -H[I][J] = 0; -}Else { +H[I][J] = H[i-1][j] + h[i-1][j-1]; - } +System.out.print (H[i][j] + "\ T"); A } at System.out.println (); - } - } -}
arrays, two-dimensional arrays