gpt4 book ai didi

java - 比较密码不起作用 Java

转载 作者:行者123 更新时间:2023-12-03 22:54:16 25 4
gpt4 key购买 nike

好吧,我正在尝试比较两个密码,如果密码正确或密码错误则输出一条消息,但编译时出现问题。

    public void setPassword (int passwordSet) {
passwordSet = password;
}

public void checkPassword (int passwordGuess) {
if (password == passwordGuess) {
System.out.println("Correct password.");
} else {
System.out.println("Wrong password.");
}
}

class TestStuffTestDrive {
public static void main (String[] args) {
TestStuff one = new TestStuff();
one.setPassword(7558);
one.checkPassword(7363);
one.checkPassword(7558);
}
}

然后当我运行它时会出现:

run: Wrong password. Wrong password.

最佳答案

尝试像这样编写您的 setPassword 方法:

  public void setPassword(int passwordSet) {
this.password = passwordSet ;
}

关于java - 比较密码不起作用 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34974008/

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