0
Tell me the Output of the code please
import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); int age =myVar.nextInt(); System.out.println(age); if (age < 16) { System.out.println("Too Young"); } else { System.out.println("Welcome!"); } } }
10 Answers
+ 3
It is JavaScript?
+ 2
It is Java and not JavaScript.
You cannot have a variable name with space in between. So 'my var' is not a valid name, instead you could use 'myVar'. Also if you want to take an integer input then you must write-
int age = myVar.nextInt();
+ 2
There are errors on your program
â˘name of your scanner should not have spaces.
â˘you did not declare variable age.
â˘my var.nextLine(); should be age=myvar.nextInt(); because you are pertaining to the age.
â˘because it's a user input type you can't tell the output unless you have constant value for age.
+ 2
It is not JavaScript its Java,
There are some errors in the code :-
1) The "my var" is not valid it must be without space "myvar"
2) You must add "int age = myvar.nextInt();" before if statement.
3) After above given changes the "System.out.println(myvar.nextInt());" will cause error, change it to "System.out.println(age);" and type it after declaration of variable age.
And you can't tell the output before the user input.
+ 2
//This is the code without errors :
import java.util.Scanner;
class MyClass {
    public static void main(String[ ] args) 
    {
        Scanner myVar = new
        Scanner(System.in);
        int age =myVar.nextInt();
        System.out.println(age);
        if (age < 16) 
        {
            System.out.println("Too Young");
        } 
        else {
            System.out.println("Welcome!");
        }
    }
}
+ 1
@Avinesh not working bro can you help me
+ 1
King Aap This should be your first 3 lines.
Scanner myVar = new Scanner(System.in);
int age =myVar.nextInt();
System.out.println(age);
0
Ya
0
Avinesh thank you for your help 
It's working now
0
@Avinesh  
8
8
Is to young 
Program finished







