I have a problem with the code. This is the process -
- First you enter your name
- Then you enter your age
- Then you enter your password (default value is "anybody")
Name and age can be entered without problem but the program evaluates the password with error. When you enter your password correctly, it still returns as false.
Please Help me!! Thanks.
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);
}
}
}