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!"); } } }

6th Dec 2018, 6:39 PM
EthanPlusPlus
EthanPlusPlus - avatar
2 odpowiedzi
+ 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();
6th Dec 2018, 6:52 PM
Michal
Michal - avatar
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"); } } }
6th Dec 2018, 6:57 PM
MsJ
MsJ - avatar