public static void main(String args)
System.out.println("Enter your age?");
int age = readit.nextInt();
boolean age = yourAge(userAge);
System.out.println(age);// displays true or false only. How can i add a message depending on the users input?
private static boolean yourAge(int userAge)
if(userAge > 21)
Jesper de Jong wrote:In the programming language Groovy, there's a thing called the elvis operator which is a shortened version of Java's ? : ternary operator. But Groovy's elvis operator doesn't exist in Java.
I was about to ask why it's called an "Elvis operator", then took another look .
C# uses ?? as a similar construct.
fred rosenberger wrote:the ? is supposed to be his hair and the : his eyes:
also, this is logically wrong:
this would not let anyone under the age of 22 drink - almost a full year after they should. I know a LOT of college students who would not like this...
Oh snap, i did not even notice that. Thanks for pointing it out!
Yes, you can pass a command‑line argument. There are lots of different ways to do it: this is one possible way. You would have to check the API documentation for the valueOf method before using it:-Note this example creates a Boolean object which is unboxed by the Foo constructor. As I said, there are lots of other ways to do it.