+ 2
Haaaahhhhhh!!! Hate. How to mĐ°ke it work
4 Answers
+ 12
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner
sc= new Scanner(System.in);
int input = sc.nextInt();
System.out.println(input);
if(input <= 0) {
System.out.println("Error");
} else if(input <= 16) {
System.out.println("Too Young");
} else if(input < 100) {
System.out.println("Welcome!");
} else {
System.out.println("Really?");
}
}
}
You made many mistakes in your code, here's the explanation :
-- You should use nextInt() for taking int input, nextLine takes a String Input. You could also convert your String to int but this isn't favourable. So better take int input when dealing with numbers.
-- You ended the main() method before the if-else statements and that yeilds an error as you cannot run a program without a method in Java!
-- You should store your input in a variable to use it anywhere in your code, you're taking the Scanner object as the reference to the input, that's not the right way!
+ 1
Hmm. indeed. thank you