Why won't this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why won't this code work?

import java.util.Scanner; public class Password { public static void main(String[] args) { string I; int I = 12; Scanner input = new Scanner (System.in); System.out.println("input:"); string I = input.next(); if(input.equals(I)) System.out.println("Hello!"); }else{ System.out.println("Nope"); } } }

12th Mar 2017, 5:39 PM
One Puncher
One Puncher - avatar
4 Answers
+ 2
My solution: import java.util.Scanner; /** * * @author Bilder */ public class Password { public static void main(String[] args){ String In; int I = 12; Scanner input = new Scanner (System.in); System.out.println("input:"); In = input.next(); if(In.equals("I")){ System.out.println("Hello!"); }else{ System.out.println("Nope"); } } } So you see where are your mistakes ;)
12th Mar 2017, 6:40 PM
Marko Marinic
+ 1
"public class Password {" this cannot be before you main args and the next { has no reason to be there. also your if statement should open with a curly bracket .
12th Mar 2017, 6:04 PM
Eric Kershner
Eric Kershner - avatar
0
Delete class password
12th Mar 2017, 5:44 PM
Ihor
0
You need to capitalize String, and there is no need to put String in front of l again when loading it, and l must be initialized with two quotation marks (not single quotes or else it will be a character type). You also can't put the same variable name l even if you change type.
12th Mar 2017, 6:19 PM
sniperisdemoman
sniperisdemoman - avatar