0

Why does this code have an error called bad operand. Also, are we learning java 7 or 8?

import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println("Enter your age: "); Scanner age = new Scanner(System.in); int agevalue = age.nextInt(); if(age <= 0) { System.out.println("Error"); } else if(age <= 16) { System.out.println("Too Young"); } else if(age < 100) { System.out.println("Welcome!"); } else { System.out.println("Really?"); } } }

26th Aug 2018, 2:02 AM
Mohammad Nadeem
Mohammad Nadeem - avatar
2 odpowiedzi
+ 8
You are using `age` (object of Scanner class) instead of `agevalue` (integer storing the input value) in your `if` conditions.
26th Aug 2018, 2:08 AM
Eduardo Petry
Eduardo Petry - avatar
+ 1
Oh bro thanks alot
26th Aug 2018, 2:11 AM
Mohammad Nadeem
Mohammad Nadeem - avatar