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); } }
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.
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
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
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);
}
}