17 How java.util.Scanner class overcome the problem of Boolean Type Data in Java?

For Ex: In this program I am showing how the Scanner class is giving proper exception details.

ScanDemo.java

import java.util.Scanner;
class ScanDemo{

public static void main(String s[] ){

Scanner scan=new Scanner( System.in );

System.out.println("\n Enter Some Boolean data: ");
Boolean a = scan.nextBoolean();
System.out.println("\n a: "+a);

}

}


Output: 

Previous
Next Post »