gpt4 book ai didi

java - 我的 else 语句似乎不起作用(JAVA)

转载 作者:行者123 更新时间:2023-11-30 06:53:16 26 4
gpt4 key购买 nike

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 语句似乎在所有情况下都会执行。

最佳答案

试试这个

if (a1=='Y' || a1=='y') {
trolley=MyfirstEnum.one;
out.println("Ewwwwwww");
} else 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?");
}

关于java - 我的 else 语句似乎不起作用(JAVA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42326104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com