I suggest factoring out the askInteger logic:
public static int askInteger(String prompt, Scanner scanner) {
int n = 0;
System.out.println(prompt);
while (n < 1) {
n = scanner.nextInt();
}
return n;
}
You can call it like:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = askInteger("a: ", scanner);
int b = askInteger("b: ", scanner);
System.out.println(a);
System.out.println(b);
}
Coupling this function and @h.j.k 's function you can have very readable code.