Skip to content

Instantly share code, notes, and snippets.

@andymuncey
Created November 5, 2021 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymuncey/b7459f7e83657d141f3bafccf7b75063 to your computer and use it in GitHub Desktop.
Save andymuncey/b7459f7e83657d141f3bafccf7b75063 to your computer and use it in GitHub Desktop.
//Add code to print a message asking if the user is male,
//informing them to type 'true' or 'false'
System.out.println("Are you male? Type true or false");
//Use the scanner to read in a boolean value (use the code completion to help you find the correct method),
//and store the boolean in a variable called isMale
Scanner inputScanner = new Scanner(System.in);
boolean isMale = inputScanner.nextBoolean();
//Create an if statement to check the isMale variable, and if this value is true,
//print out a message informing him that he could expect to live to around 79
if (isMale){
System.out.println("You can expect to live to around 79");
}
//Add another if statement, this time checking if the user is female (i.e. not male),
//if so, output a message informing her that she could expect to live until around 83.
//(Do not ask the user if they are female!)
if (!isMale){
System.out.println("You can expect to live to around 83");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment