gpt4 book ai didi

java - 为什么这不起作用? java

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

public void onMessage(String channel, String sender, String login, String hostname, String message) {
if (message.toLowerCase().startsWith("!up")) {
String[] args = message.split(" ");
String pass = "password";
if (args[1] == pass){
op(channel, sender);
sendMessage(channel, sender+": you now have op");
}else{
sendMessage(channel, sender+ " incorrect pass");
sendMessage(channel, "" +args[1]);
}
}
}

这应该检查用户是否输入!up密码无论我做什么,它总是说密码错误。我做错了什么?

最佳答案

使用 String#equals 而不是 == 来比较字符串。

所以代替:

if (args[1] == pass) {
...
}

您应该使用:

if (args[1].equals(pass)) {
...
}

关于java - 为什么这不起作用? java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9713964/

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