Next t lines contain three space-separated integers N, B1, B2 and where N is the number of sides in the polygon and B1, B2 denote the vertices that are colored black.
How can I extract numbers from single input using only one scanner object?
22 Answers
You can use String[] input = scanner.nextLine().split(" ") which will return a String array of the values that are entered on a single line. For example, if 1 2 3 is entered from the console, in input you will have ["1", "2", "3"].
Since you are using Scanner, a simple Scanner.nextInt() will suffice to read integers as long as they are separated by whitespace as mentioned in your problem statement.
For instance:
int n1,n2; Scanner sc = new Scanner(System.in); n1=sc.nextInt(); n2=sc.nextInt(); If the input is 20 40, n1 will store 20 and n2 will store 40.
See: