Home > Back-end >  If judgment, use int right, there was an error with string
If judgment, use int right, there was an error with string

Time:05-18

Always can't find any questions, please answer
Code attached
 public static void main (String [] args) {
System. The out. Println (" please input the user name: ");
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();

If (I==123) {
System. The out. Println (" please enter the password ");
Int j=sc nextInt ();
If (j==456) {
System. The out. Println (" login success ");
} else {
System. The out. Println (" login failed ");
}
} else {
System. The out. Println (" username error ");
}


Sc. The close ();
}
Public static void main (String [] args) {
System. The out. Println (" please input the user name: ");
Scanner sc=new Scanner(System.in);
The String I=sc. NextInt ();

If (I==123) {
System. The out. Println (" please enter the password ");
String j=sc nextInt ();
If (j==456) {
System. The out. Println (" login success ");
} else {
System. The out. Println (" login failed ");
}
} else {
System. The out. Println (" username error ");
}


Sc. The close ();
}

CodePudding user response:

Java String can only use the equals method determine content inside,
  • Related