[Java] 纯文本查看 复制代码 import java.util.Scanner;
public class Test3_StringStudent {
/**
键盘录入五个学生的信息
姓名、学号、语数外
*/
public static void main(String[] args) {
demo1();
}
private static void demo1() {
Scanner sc = new Scanner(System.in);
String[][] arr = new String[6][5];
arr[0][0] = "姓名";
arr[0][1] = "学号";
arr[0][2] = "语文成绩";
arr[0][3] = "数学成绩";
arr[0][4] = "英语成绩";
for (int i = 1; i < 6; i++) {
System.out.print("请输入第" + i + "名学生的姓名:");
String name = sc.nextLine();
System.out.println();
arr[i][0] = name;
System.out.print("请输入第" + i + "名学生的学号:");
String id = sc.nextLine();
System.out.println();
arr[i][1] = id;
System.out.print("请输入第" + i + "名学生的语文成绩:");
String yuwen = sc.nextLine();
System.out.println();
arr[i][2] = yuwen;
System.out.print("请输入第" + i + "名学生的数学成绩:");
String shuxue = sc.nextLine();
System.out.println();
arr[i][3] = shuxue;
System.out.print("请输入第" + i + "名学生的英语成绩:");
String yingyu = sc.nextLine();
System.out.println();
arr[i][4] = yingyu;
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
自己写的,可以参考一下 |