JAVA SP T


Lets dive into snapshot of my programs!💻

6. Enter the boolean from user using Scanner class

💡Code:

   import java.util.*;  
              class Boolean7078 {    
                  public static void main(String[] args) {         
                         System.out.print("Are you above 18?- ");  
                         Scanner sc = new Scanner(System.in);  
                         boolean bn = sc.nextBoolean();  
                         if (bn == true) {  
                             System.out.println("You are over 18");  
                         } else if (bn == false) {  
                             System.out.println("You are under 18");  
                         }  
                         sc.close();                      
                   }  
              }   

📸Output :

output