gpt4 book ai didi

java - java中的枚举错误

转载 作者:行者123 更新时间:2023-12-01 18:32:41 26 4
gpt4 key购买 nike

enum key{
ABCD,XYZ
}

public class example {
public static void main(String args[])
{
String Pass,a;
Scanner in = new Scanner(System.in);
System.out.println("enter the password");
Pass=in.nextLine();
if(Pass==key.ABCD)
{
System.out.println("your password was correct"+key.ABCD);
}
else
{
System.out.println("your password was incorrect");
}
}
}

最佳答案

字符串 Pass 应首先转换为 key 类型的枚举,因此将 if 部分更改为:

if(key.valueOf(Pass) == key.ABCD){
...
}

关于java - java中的枚举错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23422329/

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