+ 1
How do you get user input for boolean....example, if a user is 18 years (true/ fals)...code for tht
boolean
6 Answers
0
@Ian so there is a function in java,  Java.lang.Boolean.parseBoolean(string),  which you could use. 
Though, I believe I'd recommend simply using a if-case for booleans. That works the same in pretty much any language as well. 
Also that allows you to parse something like "yes" and "no" to a bool. Remember to use toLowerCase to make it case-insensetive. 
A simple example:
Scanner scanner = new Scanner(System.in);
System.out.println("Are you 18 years or older? (Yes/No): ") ;
String input = scanner.nextLine().toLowerCase() ;
if (input == "yes") 
{
    // do stuff
} 
else if (input == "no") 
{
    // do other stuff
} 
else 
{
    // user entered something else than yes or no
}
+ 4
In what language?
+ 1
If i got what you are asking: there is a code in c++. Hope it helps
https://code.sololearn.com/ctUZHNr5PXyl/?ref=app
0
in java
0
thanks alot laser. You a life saver
0
@Ian no problem mate



