java - WAJP to display message based on age -


wajp program displays different message depending on age given. here possible responses:

age less 16, "you can't drive."

age less 18, "you can't vote."

age less 25, "you can't rent car."

age 25 or over, "you can that's legal."

here's sample run. notice person under 16 display 3 messages, 1 being under 16, 1 being under 18, , 1 being under 25.

4 basic if-statements solve problem, want output possible messages if age input meets of 4 requirements.

import java.util.scanner;  public class main {     public static void main(string[] args) {         scanner scan = new scanner(system.in);          system.out.println("enter age: ");         int age = integer.parseint(scan.nextline());          if (age < 16)         {             system.out.println("you can't drive.");         }         if (age < 18)         {             system.out.println("you can't vote.");         }         if (age < 25)         {             system.out.println("you can't rent car.");         }         if (age >= 25)          {             system.out.println("you can that's legal.");         }     } } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -