好吧,我試圖做到這一點,如果這個人不想進入他們的年齡,程序會打印出不同的答案。但是,當我這樣做,它給了我一個錯誤的字符串。我使用//來創建它,所以int的答案不會被播放,它的工作。我究竟如何做到這一點,所以他們都爲同一個問題工作?我搜索了一個答案,但我似乎無法找到它,所以如果有這個鏈接,請鏈接我。謝謝!兩個if語句有不同的變量
System.out.println("So how old are you?");
TimeUnit.SECONDS.sleep(2);
System.out.println("If you dont want to answer you dont have to. ");
Scanner scan4 = new Scanner (System.in);
String user_imput_string1 = scan.nextLine();
if (user_imput_string1.equals("I dont know")) {
System.out.println("Ah thats cool. You look great regardless of your age anyway");
} else {
System.out.println("Ah thats cool. You look great regardless of your age anyway");
}
@KevinEsche與您的評論有點混淆。你是說我不能同時擁有一個字符串和一個int有一個問題的單獨變量? –
對不起,在第二部分中使用'String'的時候會錯過它。 [檢查這個問題,它應該是相關的](http://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo) – SomeJavaGuy
@NateCraft嘿內特,它似乎就像刪除了具有'user_imput_int'的代碼的第二部分。 – kbunarjo