我有一個代碼的問題。這是這個過程 -布爾和如果錯誤
- 首先,你輸入你的名字
- 然後輸入您的年齡
- 然後輸入您的密碼(默認值是「任何人」)
姓名和年齡可以輸入沒有問題,但程序評估錯誤的密碼。當您正確輸入密碼時,它仍會返回爲false。
請幫幫我!! 謝謝。
import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
String name;
int age;
boolean trueOrFalse;
boolean trueOrFalse2;
String builtInPassword = "anybody";
Scanner keyBoardInput = new Scanner(System.in);
System.out.print("Please enter your First name: ");
name = keyBoardInput.next();
System.out.print("Please enter your age: ");
age = keyBoardInput.nextInt();
trueOrFalse = false;
trueOrFalse2 = true;
System.out.print("Please enter your Password: ");
if (keyBoardInput.next() == builtInPassword) {
System.out.println(trueOrFalse2);
} else {
System.out.println(trueOrFalse);
}
}
}
Rahul謝謝。 – aghdaeea