Home > Back-end >  In the Java API classes. I don't know where is wrong
In the Java API classes. I don't know where is wrong

Time:10-02

Package cn. Itcast. Chapter04;

Import the Java. Util. Scanner;

Public class Exom05 {
Public static void main (String [] args) {
String STR=new String [] [20].

Int m;


Scanner sc=new Scanner (System. In);
System. The out. Print (" input password number n: ");
Int n=sc. NextInt ();
for(int i=0; I & lt; n; I++)
{System. Out. Println (" input password first "+ (I + 1) +" ");
STR [I]=sc. NextLine ();


}
System. The out. Print (" password ");

String str2=new String (sc) nextLine ());
M=0;
For (int I=0; I{
If (str2. The contains (STR) [I]) m=1;
}
If (m==1) System. Out. Print (" input password right ");
The else System. Out. Print (" password incorrect ");
}
}

CodePudding user response:

In the int n=sc. NextInt (); After added sc. NextLine ();//remove residues in the input buffer after receive the int data enter a newline character

CodePudding user response:

reference 1st floor qybao response:
in int n=sc. NextInt (); After added sc. NextLine ();//remove the residue after receive the int data in the input buffer carriage return line breaks

I know where the wrong
Should be STR [I]=sc. Next ()
  • Related