我目前正在使用计算器,如果第二次扫描等于特定单词,我想跳过 2 行代码。在这种情况下,这个词要么是“Wurzel”,要么是“wurzel”,因为那时我不需要扫描 b。
Scanner eingabe = new Scanner(System.in);
BigInteger a, b, ergebnis;
String Operator;
System.out.println("Bitte gib die erste Zahl ein:");
a = eingabe.nextBigInteger();
System.out.println("Bitte gib die Rechenart ein:");
Operator = eingabe.next();
if(Operator == "Wurzel" || Operator == "wurzel" ) {
//skip to switch(operator)
}
System.out.println("Bitte gib die zweite Zahl ein:");
b = eingabe.nextBigInteger();
switch(Operator) {
...
}
最佳答案
您应该否定 if 语句并将各个部分放在该 block 内的中间。
if(!( Operator.equals("Wurzel") || Operator.equals("wurzel") ) {
System.out.println("Bitte gib die zweite Zahl ein:");
b = eingabe.nextBigInteger();
}
关于java - 如果某事为真则跳过几行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53890121/