0

I tried to use eclipse IDE for java and when every I run this code in it I can answer the first question but when I press enter in Gives the 2 second question but the reply too which was supposed to come after I type Pizza.

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.print("Whats your age: ");
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int age = Integer.parseInt(s);
    
    if (age >= 18) {
        System.out.print("Whats your fav food: ");
        String food = sc.nextLine();
        
    
        if (food.equals("Pizza")) {
        System.out.println("Mine Too!");
        
        }       
        else
        {
            System.out.println("Not mine");
        }
    }
    else if (age >=13) {
        System.out.println("You are a teenager");
}
    else {
        System.out.println("You are not a teenager");
    }
}

0 Answers0