+ 1

Why does rhis code result in error?

Error says illegal type start for the else statement https://code.sololearn.com/ctvEZtw613zH/?ref=app

14th Jun 2019, 8:24 PM
Tommaso Bacci
Tommaso Bacci - avatar
8 Respuestas
+ 4
System.out.println("Username:"); System.out.println(inPut.nextLine()); System.out.println("Password:"); System.out.println(inPut.nextLine()); String username = inPut.nextLine(); String password = inPut.nextLine(); This is a problem because each input.nextLine() expects an input. In sum: 4 inputs. First store the input, then print it: String name = input.nextLine(); String password = input.nextLine(); System.out.println("Name: " + name); System.out.println("Password: " + password);
14th Jun 2019, 9:11 PM
Denise Roßberg
Denise Roßberg - avatar
+ 4
A semicolon ends a statement. If(condition); <- the rest of the code does not belong to the if statement. The curly bracketts creates a block: If(){ //if block -> everything in it belongs to if }else{ //else block -> every thing in it belongs to else }
14th Jun 2019, 9:07 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Your welcome :)
14th Jun 2019, 9:45 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
For starters, you used a semicolon instead of curly brackets, and the condition will definitely be true, because you used an assignment operator instead of comparison. But then that would always be false, because you can't really compare strings like that. Use username.equals("ACAB)
14th Jun 2019, 8:36 PM
Airree
Airree - avatar
+ 2
On line 15, it tests the condition, but then does nothing with it. It will print "Access Granted" no matter what, then reaches the curly bracket & the else statement and is like u wot m8
14th Jun 2019, 8:54 PM
Airree
Airree - avatar
+ 2
Thank you!!!
14th Jun 2019, 9:41 PM
Tommaso Bacci
Tommaso Bacci - avatar
+ 1
Thank you!! I changed the condition but i don't understand which semicolon i used instead of the curly brackets
14th Jun 2019, 8:50 PM
Tommaso Bacci
Tommaso Bacci - avatar