import java.util.Scanner;
public class test {
/**
* @param args
*/
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
boolean US1 = false;
boolean game;
int score = 1;
int wage = 0;
int fin_score = 0;
String ans;
if (US1 == false) {
game = false;
System.out.println (score);
System.out.println("Enter a wager");
wage = input.nextInt();
}
if (wage < score) {
System.out.println ("What is the capital of Liberia?");
ans = input.next();
if (ans.equalsIgnoreCase("Monrovia")) {
System.out.println ("You got it right!");
System.out.println ("Final score " + fin_score);
}
}
}
}
我發現了一堆用InputMismatchException時的解決方案,並嘗試{}趕上{}但是當他們在我的代碼來實現他們從來沒有工作。有沒有辦法在這裏實現這些?我試圖做一個循環迭代,直到輸入的工資是一個整數確定是否輸入的號碼是一個int
當然這種方法(與try/catch)的作品。因此(未示出)的實現必須是錯誤的。 – user2864740
你有什麼嘗試?在這種情況下,使用在線解決方案將起作用,我保證。 – nook