I have this code:
Scanner scan = new Scanner(System.in);
String s2 = scan.nextLine();
int i2 = scan.nextInt();
System.out.println("natural= " + i2);
System.out.println("cadena = " + s2);
scan.close();
That works correctly:
This is a chain
1714
natural = 1714
string = This is a string
But if I change the order of the Scanner
lines:
int i2 = scan.nextInt();
String s2 = scan.nextLine();
Ignore line scan.nextLine()
and give me the result just after entering the int
1714
natural = 1714
string =
Does anyone know what is happening and how to solve it?