我試圖從用戶輸入學生數據。首先,我問用戶他們輸入數據的學生人數。然後,代碼向用戶詢問用戶輸入第一個問題的確切數量的數據。顯示數組中的列表,以數字方式輸入數據
下面是我的代碼的開始。我在初始變量之後獲取用戶輸入時遇到問題。我需要拿這個變量,比如說用戶輸入5
,我需要提示用戶5次輸入學生姓名和成績。像這樣:
Student 1 last name:
Student 1 first name:
Student 1 grade:
Student 2 last name:
我必須使用一個數組,我只需要弄清楚如何正確獲取用戶輸入。
import java.util.Scanner;
public class StudentScoresApp {
public static Score score = new Score();
private static Student student;
public static void main(String[] args) {
System.out.println("Welcome to the Student Scores Application.\n");
getStudentScores();
}
public static void getStudentScores() {
Scanner input = new Scanner(System.in);
System.out.println("Enter number of students to enter: ");
int num = input.nextInt();
int [] a = new int[num];
for (int i = 0 ; i < num ; i++); {
System.out.print("Enter Student " + (i + 1) + " last name:");
a[i] = in.nextInt();
}
}
}
*我有問題*:哪些問題?另外,你打算如何將姓氏存入一個int? – 2013-03-02 16:32:02