I'm very new to Java and only started it yesterday, this is an exercise for my class and the code has to be similar to this one. I'm trying to create a simple log-in system in Java. This is the error I am getting: Error:(18, 11) java: illegal start of type
I've had a friend with similar code and it worked for him and he cannot specify why mine is not working.
I tried removing the curly brackets. I tried making different if statements and I tried putting round brackets around read.nextLine();
System.out.print("Type your username: ");
String username = reader.nextLine();
System.out.print("Type your password: ");
String password = reader.nextLine();
if (username = "Alex" && password = "mightyducks") {
System.out.print("You are now logged into the system!");
} else if (username = "Emily" && password = "cat")
System.out.print("You are now logged into the system!");
} else {
System.out.print("Your username or password was invalid!");
}
I simply want the program to show "You are now logged into the system!" when the correct password is given for Alex or Emily and for it to otherwise state: "Your username or password was invalid!".
Aucun commentaire:
Enregistrer un commentaire