PackageCOM.HXL;ImportJava.util.Scanner; Public classTest { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); System.out.println ("Please enter an integer and a string:"); intAA =Sc.nextint (); String SS=sc.nextline ();System.out.println ("The integer you entered is:" + AA + "The string you entered is:" +SS); }}
"Problem" At this point the console will no longer accept input after entering the first integer to enter ...
The Modified code:
PackageCOM.HXL;ImportJava.util.Scanner; Public classTest { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); System.out.println ("Please enter an integer and a string:"); intAA =Sc.nextint (); String SS=Sc.nextline (); String SS1=Sc.nextline (); System.out.println ("The integer you entered is:" + AA + "The string you entered is:" +SS1); }}
"Explain" the escape character of carriage return in Windows is \r\n,scanner when it hits the full string of strings it encounters, it reads, and the program goes backwards ...
"Other methods" can be used to receive all data in a string, and then the corresponding conversion.
A small problem with scanner scanning console input in Java