-3
你好,我一直在試圖做一個程序,問ASK 1)有多少學生? 2)詢問一個名字和測試標記如何使用java輸入數組
有人可以幫我解決這個問題。進出口新的編程這裏是我的代碼
Scanner input = new Scanner(System.in);
System.out.println("How many Students in class?");
int n = input.nextInt();
System.out.println("Enter the " + n + " names: ");
String [] names = new String[n];
for (int i = 0; i < names.length; i++)
{
names[i] = input.nextLine();
}
k.joe,歡迎來到StackOverflow。我想你會得到這個問題的提示,因爲它不符合網站的精神和規則。你已經提出了這個問題,但請確保你提出你在代碼中面臨的問題/錯誤,併爲此提出解決方案。請不要指望人們爲你寫邏輯。 –
歡迎,請參閱[問],你沒有解釋你的問題。 – AxelH
使用next(),nextInt()或其他nextFoo()方法後,[Scanner正在跳過nextLine()](http:/ /stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo) –