0

can't run this programm in sololearn playground anyone tell me why

import java.util.Scanner; public class bln { public static void main(String[] args) { Scanner sr = new Scanner(System.in); //create true false boolean b3 = sr.hasNextInt(); System.out.println(b3); } }

9th Apr 2022, 7:41 AM
will
will - avatar
4 Respuestas
0
Try to use conditional `if` if( sr.hasNextBoolean() ) { boolean b3 = sr.nextBoolean(); System.out.println( b3 ); } You should be checking for input availability using .hasNextBoolean(), and reading the input afterwards using .nextBoolean() method of Scanner object. Input either 'true', 'false', 'True', 'False' Input of other values seemed to be ignored.
9th Apr 2022, 8:54 AM
Ipang
0
import java.util.Scanner; public class bln { public static void main(String[] args) { Scanner sr = new Scanner(System.in); if( sr.hasNextBoolean() ) { boolean b3 = sr.nextBoolean(); System.out.println( b3 ); } } } No output. BRO
9th Apr 2022, 9:39 AM
will
will - avatar
0
I see output on my part Check whether your input matches 'true', 'false', 'True' or 'False' (without quotes) If you give other input then expect to see no output BRO
9th Apr 2022, 9:45 AM
Ipang
0
//you need accept atleast a input, try this import java.util.Scanner; public class bln { public static void main(String[] args) { Scanner sr = new Scanner(System.in); //create true false boolean b3 = sr.hasNextInt(); sr.next(); System.out.println(b3); } }
9th Apr 2022, 6:19 PM
Jayakrishna 🇮🇳