Need Some Help in Java!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need Some Help in Java!!

Guys I am having some problem while running this code can anyone suggest me what is the problem import java.util.Scanner; public class Program { public static void main(String[] args) { String age = new Scanner(System.in).nextLine(); if (age > 17){ System.out.println("You are an Adult"); }else{ System.out.println("You are not an Adult"); } } }

20th May 2020, 5:24 AM
Abdul Malik
Abdul Malik - avatar
3 Answers
+ 2
Age is a string, change this to int and nextLine() to nextInt()
20th May 2020, 5:28 AM
4lx
4lx - avatar
+ 1
Type error you are matching string with integer that's the problem
20th May 2020, 9:18 AM
Shahghasi Adil
Shahghasi Adil - avatar
0
But how to change it into integer
20th May 2020, 6:45 AM
Abdul Malik
Abdul Malik - avatar