0
What is wrong with this code?
Can I please get a very simple explanation on what is wrong with this code: import java.util.*; public class Program { public static void main(String[] args) { int age; Scanner age = new Scanner(System.in); System.out.println(age.nextInt()); if (age < 16) { System.out.println("Too Young"); } else { System.out.println("Welcome!"); } } }
2 Réponses
+ 3
You are not assigning value to int age.
Don't use the same object names.
Try smth like,
int age;
Scanner sc = new Scanner (System.in);
age = sc.nextInt();
0
import java.util.*;
class I1{
public static void main(String[] args){
Scanner s1 = new Scanner(System.in); System.out.println("Enter an integer");
int a;
a = s1.nextInt();
if(a<16){
System.out.println("young");
}
else{
System.out.println("welcome");
}
} }