我試圖創建一個方法來搜索用戶輸入的學號(sNumber)的ArrayList,然後用相同的輸入得到indexOf,以便它可以從其他數據列表中提取數據。我遇到的問題是我無法弄清楚如何使用用戶的單個輸入來完成此操作。現在爲了工作,他們必須輸入兩次sNumber。使用單個掃描器輸入來分配Java中的兩個變量
while (exit == 0){
System.out.println("Please enter the sNumber of the student you wish to find");
Boolean x = sNumber.contains(kb.nextInt());
int y = sNumber.indexOf(kb.nextInt());
if (x = true){
String a = name.get(y);
int c = sNumber.get(y);
String d = major.get(y);
Double e = gpa.get(y);
System.out.println(a);
System.out.println(c);
System.out.println(d);
System.out.println(e);
}
else if (x = false){
System.out.println("This student does not exist");
'(X =真)'是指派TRUE;爲'x',然後取'x'的值用於'if'。布爾值使用'=='或者只是'x'。 – 2013-05-10 18:24:28