import java.util.Scanner;
import static java.lang.System.*;
public class Whativelearned {
enum MyfirstEnum {one, two, three}
public static void main(String[] args) {
Scanner keyboardinput = new Scanner(in);
MyfirstEnum trolley;
char a1;
out.println("Do you pee in the shower"? Y/N");
a1 = keyboardinput.findWithinHorizon(".", 0).charAt(0);
if (a1=='Y'||a1=='y') {
trolley=MyfirstEnum.one;
out.println("Ewwwwwww");
}
if (a1=='N'||a1=='n') {
trolley=MyfirstEnum.two;
out.println("Well somebody isn't being very honest");
}else {
out.println("You're not so keen on following instructions, are you?");
}
keyboardinput.close();
}
}
我希望我的else
語句覆蓋所有的結果,除了在if
案件的案件。
正如我希望它作爲(!(a1=='Y'||(a1=='y'||a1=='n'||a2=='N'))
我else語句似乎並沒有發揮作用(JAVA)
但是當我運行它的上市else
聲明似乎在所有情況下被執行。
你else語句是指最後'if'塊只有這樣,它只被觸發時'(!(A1 == 'N' || A2 == 'N'))'。 –