Multiple choice technology programming languages

Given:

import java.util.*;   
public class Looking {   
  public static void main(String[] args) {   
    String input = "1 2 a 3 45 6";   
    Scanner sc = new Scanner(input);   
    int x = 0;   
    do {  
       x = sc.nextInt();  
       System.out.print(x + " ");  
     } while (x!=0);  
   }  
 }

What is the result?

  1. 1 2

  2. 1 2 3 45 6

  3. 1 2 3 4 5 6

  4. 1 2 a 3 45 6

  5. 1 2 followed by an exception

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The Scanner processes tokens '1', '2', and then encounters 'a'. When sc.nextInt() is called to parse 'a' as an integer, it throws an InputMismatchException. Consequently, '1 2' is printed before the program terminates with an exception.