jeudi 14 janvier 2021

Why does if else statement doesn't work in this program.Please need some explanation ,While i can't move forward in learning

package tutorial; import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    
    
    System.out.println("Enter your age:");
    Scanner sc = new Scanner(System.in);
    int age = sc.nextInt();
    
    
    if(age > 13 ) {
        
            
                System.out.println(" you are a teenager");
            
    }
    if else(age >18) {
            
            System.out.println("You are adult! you can drive");
        }
        
    }
    else {
        
        System.out.println("you cant drive");
    }

If enter age as " 21" .It just prints the first if else statement .I just want solution and explanation

Aucun commentaire:

Enregistrer un commentaire