我不知道如何給這個問題的標題,但基本上這是我的二十一點程序的一部分。另外,由於我不知道如何標題,所以我不確定如何查看它,這就是我在這裏問的原因。所以我說當用戶輸入1或11作爲ace值時,如果他們輸入了1或11以外的值,它會再次要求用戶輸入1或11.在我的程序中,一切正常,除非用戶進入1,那麼它只是再次提出問題。應該只又問如果輸入不等於1或11的程序這裏是我的代碼,我確信它總是給用於測試目的的王牌:Java嵌套如果語句 - 或比較!=
String card1="A";
int total=0;
Scanner input_var=new Scanner(System.in);
if (card1=="A"){
System.out.println("Do you want a 1 or 11 for the Ace?: ");
int player_ace_selection=input_var.nextInt();
if ((1|11)!=(player_ace_selection)){
System.out.println("Please enter a 1 or 11: ");
int new_selection=input_var.nextInt();
total=total + new_selection;
}
else {
total=total + player_ace_selection;
}
}
System.out.println(total);
在此先感謝。
提示:'.nextInt()''VS .nextLine' - >先不讀新行'\ N' – Yahya
沒有簡寫形式'或',你正在做一個按位或在'(1 | 11)!'(player_ace_selection)''1'和'11'處' –
'card1 ==「A」'這裏不是唯一的問題,它不是主要的問題。投票重新開放。 – dasblinkenlight