Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么这不起作用?JAVA_Java_String_If Statement_Irc - Fatal编程技术网

为什么这不起作用?JAVA

为什么这不起作用?JAVA,java,string,if-statement,irc,Java,String,If Statement,Irc,这是为了检查用户是否输入!注册密码 无论我做什么,它总是说密码不正确。我做错了什么?使用String#equals而不是=来比较字符串 因此,不是: public void onMessage(String channel, String sender, String login, String hostname, String message) { if (message.toLowerCase().startsWith("!up")) { String[] args

这是为了检查用户是否输入
!注册密码
无论我做什么,它总是说密码不正确。我做错了什么?

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

因此,不是:

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]);
        }
        }
    }
你应使用:

if (args[1] == pass) {
   ...
}
使用字符串#equals而不是
=
来比较字符串

因此,不是:

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]);
        }
        }
    }
你应使用:

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

使用

args[1].equals(pass)
而不是
args[1]==pass

args[1].equals(pass)
应改为

if (args[1] == pass) 
因为in==case编译器会检查不同的引用值,但是当使用equals()而不是reference时,会检查字符串的内容

应改为

if (args[1] == pass) 
因为in==case编译器会检查不同的引用值,但是当使用equals()而不是reference时,会检查字符串的内容。

必须使用if(args[1].equals(pass))

必须使用if(args[1].equals(pass))

可能重复的