所以我正在做這件事,要求你輸入你想要的數字,然後讓你輸入一個數字。該代碼應該檢查這個數字是否是第一次提交的數字之一,如果是,會彈出一條消息說出來,然後退出該程序。有人可以幫助我如何正確使用掃描儀,或者如果這不是我的代碼中的問題,幫我糾正我的代碼?使用掃描儀需要幫助
package individuellt_val;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class InlKap9test2 {
public static void main(String[] args) {
String s = JOptionPane.showInputDialog("Ange några tal");
Scanner sc = new Scanner(s);
int x = 0, y = 0;
boolean fortsätt = true;
while(fortsätt){
while(sc.hasNextInt()){
x = sc.nextInt();
String s2 = JOptionPane.showInputDialog("Ange ett tal till");
Scanner sc2 = new Scanner(s2);
while(sc2.hasNextInt())
y = sc.nextInt();
if(x == y){
JOptionPane.showMessageDialog(null, "Detta tal fanns bland de första!");
fortsätt = false;
}
}
}
System.exit(0);
}
}
1)*「我似乎無法讓它工作。」*你能設法提出一個問題嗎? 2)請使用代碼格式設置代碼和代碼片段,結構化文檔(如HTML/XML或輸入/輸出)。爲此,請選擇文本並單擊郵件發佈/編輯表單頂部的「{}」按鈕。 –
使用'新的掃描儀(System.in)' –