What's wrong in this code

+2 Arnab Banerjee · January 23, 2015
import java.util.*;
public class prog1{
static int age;
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("Enter your age ");
age = input.nextInt();
if(age <=20){
System.out.println("You are quite young now !");
}
else if(20 < age <60) {
System.out.println("You are efficient to work ");
}
else
System.out.println("You are getting old, so, take care ");

}
}

I can't understand what wrong I have done in this code ?

Post a Reply

Replies

Oldest  Newest  Rating
+1 Neil Cannon · January 23, 2015
import java.util.*;
public class Prog1{
    static int age;
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        System.out.println("Enter your age ");
        age = input.nextInt();
            if(age <=20){
            System.out.println("You are quite young now !");
            }
            else if(age >=20 && age <60) {
                System.out.println("You are efficient to work ");
            }
            else
                System.out.println("You are getting old, so, take care ");
        
            input.close();
    }
}

///// Output  Window /////


Enter your age
70
You are getting old, so, take care
+1 Branislav Lazic · January 23, 2015
This is the issue: else if(20 < age <60) {

Proper expression is: 20 > age && age < 60
  • 1

Java / Android Development

107,175 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator