+ 3

What is wrong with this program .. It does not work

import java.util.Scanner; public class Program { public static void main(String[] args) { int age; Scanner age=new Scanner(System.in); age=new.nextint(); if(age > 0) { if(age > 16) { System.out.println("Welcome!"); } else { System.out.println("Too Young"); } } else { System.out.println("Error"); } } }

9th Feb 2017, 1:39 PM
Baker Masre
Baker Masre - avatar
2 Respostas
+ 3
you have 2 duplicate variables i,e int age and Scanner age Then you misused the new keyword which is used to create a new instance of an object here is the correction ,ask if you do not understand it import java.util.Scanner; public class Program { public static void main(String[] args) { int a; System.out.println("Please enter your age"); Scanner age=new Scanner(System.in); a= age.nextInt(); if(a > 0) { if(a > 16) { System.out.println("Welcome!"); } else { System.out.println("Too Young"); } } else { System.out.println("Error"); } } }
9th Feb 2017, 1:52 PM
Agaba Ivan
Agaba Ivan - avatar
0
I am new to programming I am sorry 😅😅.. Thank you very much❤
9th Feb 2017, 1:56 PM
Baker Masre
Baker Masre - avatar