1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import java.text.DecimalFormat; import java.util.Scanner; public class Java_107_3_7_HW1 { public static void main(String[] args) { // TODO 自動產生的方法 Stub Scanner scanner = new Scanner(System.in); int members[][] = new int[5][3]; int input; double chi = 0, eng = 0, math = 0; for (int i = 0; i < members.length; i++) { for (int j = 0; j < members[i].length; j++) { input = scanner.nextInt(); members[i][j] = input; if (j == 0) chi += input; if (j == 1) eng += input; if (j == 2) math += input; } } System.out.println("NO\tChinese\tEnglish\tMathematic"); System.out.println("===================================="); for (int i = 0; i < members.length; i++) { System.out.print(i + 1); for (int j = 0; j < members[i].length; j++) { System.out.print("\t" + members[i][j]); } System.out.println(""); } chi /= members.length; eng /= members.length; math /= members.length; System.out.println("===================================="); DecimalFormat df = new DecimalFormat("0.00"); System.out.print(String.format("Average\t%s\t%s\t%s", df.format(chi), df.format(eng), df.format(math))); } } |