mercredi 4 août 2021

I am having a problem in runing if else program in java basically the else statement is not printed if the if statement is false

public class rtr { 
    public static void main(String args[])throws java.io.IOException {
        int age;
        System.out.print("Enter your age"); 
        age = (int) System.in.read(); 
        if(age >= 18) System.out.println("You are elligible for voting"); 
        else System.out.println("You are not elligible for voting");
    }
} 

output:

Enter your age 12
You are elligible for voting

Aucun commentaire:

Enregistrer un commentaire