Hello,
I'm new in Java and this is my first post here.
I was doing my homework but faced the following error:
c:\java\my box\Login.java:25: variable p might not have been initialized
if (p == pass) {
^
1 error
You can see the main code bellow:
import java.util.Scanner;
public class Login {
public static void main (String[] args) {
String user = "admin";
int pass = 123;
int p;
String u;
Scanner s=new Scanner(System.in);
System.out.println ("Enter Username:");
u=s.nextLine();
if (u == user) {
System.out.println ("Enter Password:");
p=s.nextInt();
} else {
System.out.println ("Invalid User");
}
if (p == pass) {
System.out.println (" ");
System.out.println ("Welcome to admin area.");
System.out.println (" ");
} else {
System.out.println ("Incorrect Password");
}
}
}
What's wrong with my code? Am I missing something?
Any helps will be greatly appreciated