gpt4 book ai didi

java - 声明 boolean 变量并使用 callMethod

转载 作者:行者123 更新时间:2023-12-01 14:00:03 25 4
gpt4 key购买 nike

非常感谢大家的帮助!我想通了并让它运行起来,我想我喜欢让事情变得比实际情况更困难。

import javax.swing.JOptionPane;

public class PasswordManager{

private static String masterPassword = "secret3";

public static void main(String[] args){
boolean mypass = false;
String password = JOptionPane.showInputDialog(null, "Enter Password:");
mypass = checkPassword(password);

if (mypass == true)
System.out.println("Your Password is Correct");
else
System.out.println("Your Password is incorrect");
}

private static boolean checkPassword(String password){
if(password.equalsIgnoreCase(masterPassword))
return true;
else
return false;
}
}

最佳答案

private static String thePassword = "nosecret";

public static void main(String[] args){

//*** TO DO ***: Declare a variable here of "boolean" type.
boolean mybool = false;

String password = JOptionPane.showInputDialog(null, "Enter The Password:");


//*** TO DO ***: Call the checkPassword method and pass it to the "password" variable
// from above and assign the result to your boolean variable.
mybool = checkPassword(password);


}

private static boolean checkPassword(String password){

//I'm giving you part of this code to show you one way of comparing Strings. This way ignores case,
//which may not be appropriate for passwords, but it's a useful method for many other things.
//Also, I'm giving you the "return true;" part to show you one way a boolean can be sent back...
//simply as the words "true" or "false" ... notice in code they're not in quotes just like numbers.
//*** TO DO ***: Add an "else" statement below that returns false.
if(password.equalsIgnoreCase(masterPassword))
return true;



}

关于java - 声明 boolean 变量并使用 callMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395755/

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