+ 2

Haaaahhhhhh!!! Hate. How to mĐ°ke it work

https://code.sololearn.com/c6OFdxV089DW/?ref=app

23rd Sep 2017, 1:44 PM
Nike
Nike - avatar
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!
23rd Sep 2017, 1:52 PM
Dev
Dev - avatar
+ 1
Hmm. indeed. thank you
23rd Sep 2017, 1:57 PM
Nike
Nike - avatar