lundi 3 avril 2017

combining several if statement for one input in java

im begginer in java , could anyone tell me how to combine several if in one input i mean something like this "how old are you?" when user answer this it works with several if forexample my code is :

public static void main(String[] args) {
    int age = 40;
    Scanner ageField = new Scanner (System.in);
         System.out.print("How old are you? ");
     if(ageField.nextDouble() > age ){
         System.out.print("you are over than 40 years old"); 

     }else if(ageField.nextDouble() < age ){
         System.out.print("you are less than 40");


     }else if(ageField.nextDouble() < 20 ){
         System.out.print("you are less than 20");
         }else {

             System.out.print("enter your age");
         }
    }
}

i mean the answer should based on the given value,hope you get what im saying

Aucun commentaire:

Enregistrer un commentaire