+ 1

Why this code is not working?

import java.util.Scanner; public class Nested_interval{ public static void main(String[] args){ Scanner b = new Scanner(System.in); int a= b.nextLine(); if (a<19){ if (a>15){System .out.println("You are a teen. ");} else {System.out.println("You are a Child.");} }else{ System.out.println("You are young! ");} } } https://code.sololearn.com/c3P39UxfzXf6/?ref=app

22nd Jul 2020, 6:01 PM
ahsan rzingpa
ahsan rzingpa - avatar
7 Respuestas
+ 3
22nd Jul 2020, 6:08 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
ahsan rzingpa , line 9 => right method is nextInt().
22nd Jul 2020, 6:03 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
ahsan rzingpa , nextLine() method is used for reading a string, but you declared the variable as int type. That is why it is not possible.
22nd Jul 2020, 6:13 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
ahsan rzingpa , you are welcome 🐱
22nd Jul 2020, 6:15 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Still not working
22nd Jul 2020, 6:06 PM
ahsan rzingpa
ahsan rzingpa - avatar
0
Thank you,but why there in" nextInt" not"nextLine".
22nd Jul 2020, 6:11 PM
ahsan rzingpa
ahsan rzingpa - avatar
0
Thank you so much.
22nd Jul 2020, 6:14 PM
ahsan rzingpa
ahsan rzingpa - avatar