import java.util.Scanner;
public class Application {
public static void main(String[] args) {
do {
System.out.println("What is the command keyword to exit a loop in Java?\na. int\nb. continue\nc. break\nd. exit\nEnter your choice");
Scanner ans = new Scanner(System.in);
char ans = sc.next().charAt(0);
if(ans=='c')
System.out.println("Correct");
else
System.out.println("Wrong! Presss Y to try again.");
Scanner redo = new Scanner(System.in);
char redo = sc.next().charAt(0);
}
while(redo=='y');
}
我剛開始學習Java,可以請你告訴我,什麼是錯在我的代碼,以及如何改進呢?謝謝
這是我收到的錯誤。
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Duplicate local variable ans
sc cannot be resolved
Duplicate local variable redo
sc cannot be resolved
redo cannot be resolved to a variable
at Application.main(Application.java:9)
爲什麼你認爲之前是怎麼回事? –
它不起作用。以下是錯誤...螺紋 異常「主要」 java.lang.Error的:未解決的編譯問題: \t重複的局部變量ANS \t SC不能得到解決 \t重複的局部變量重做 \t SC不能得到解決 \t重做無法解析爲變量 \t at Application.main(Application.java:9) –
請不要在註釋中發佈錯誤。請改編你的問題。 –