import java.util.Scanner; public class TwoInputs { public static void main(String[] args) { Scanner s = new Scanner(System.in); // if you wanted to repeatedly prompt a user until // they enter a valid input, then you'd put the // code below into some kind of loop. try { System.out.print("Enter two integers separated by a space: "); int x = s.nextInt(); // reads an int int y = s.nextInt(); // reads the "delimiter" (space, by default) and another int // you can change the delimiter if you want-- see the javadocs System.out.println("x = " + x + ", y = " + y); } catch (java.util.InputMismatchException e) { // clear scanner s.next(); // tell user they done bad System.out.println("Invalid input!"); } } }