After trying these suggestions for reading int input Scanner is skipping nextLine() after using next() or nextFoo()?
Can't figure out how come the input is not consuming the newline.
This is linux running jdk 11.
import java.util.Scanner;
public class NumbFile {
public static void main(String[] args) throws Exception {
int i = 100;
int powerNumber;
boolean status = true;
do {
try {
System.out.print("Type a number: ");
Scanner sc = new Scanner(System.in);
powerNumber = Integer.parseInt(sc.nextLine());
System.out.println(i * powerNumber);
sc.close();
} catch (NumberFormatException exc) {
exc.printStackTrace();
status = false;
}
} while(status);
}
}
This should stop looping only with no int input.