package unittest;
import java.util.Scanner;
/**
- @author Dylaniou
- 打印同學們的各科成績
-
第1個同學 81 57 22 34語 數 外 英
第2個同學 90 98 97 65
第3個同學 80 64 78 70
*/
public class Test {
public static void main ( String[] args )
{
int[][] scores = new int[3][4];
for(int i = 0; i<scores.length; i++){
System.out.println(“請輸入第” + (i+1) + “個同學的各科成績”);
String courseName = “”;
for(int j =0; j<scores[i].length; j++){
Scanner scan = new Scanner(System.in);
if(j0)
courseName = “語”;
if(j1)
courseName = “數”;
if(j2)
courseName = “外”;
if(j3)
courseName = “英”;
System.out.println(“請輸入”+ courseName + “成績”);
if(scan.hasNextInt()){
scores[i][j] = scan.nextInt();
}else{
System.out.println(“成績請輸入整數”);
}
}
}
System.out.println("\t\t 語 \t數 \t外 \t英");
for(int i = 0; i<scores.length;i++){
StringBuilder s = new StringBuilder(“第” + (i+1) + “個同學”);
for(int j = 0; j<scores[i].length; j++){
s.append("\t" + scores[i][j]);
}
System.out.println(s);
}
}
}