Write a program that prompts the user to enter his age Write

Write a program that prompts the user to enter his age. Write the statements needed to display the following messages based on the entered value: \"User is 18 or younger\" \"User age is between 19 and 39\" \"User is either 45 OR 50\" \"User is older than 50\" import java.util.*; public class practical {public static void main (String args[]) { Scanner scan = new Scanner(System.in); } { |

Solution


//PRACTICE11.java

import java.util.*;

public class PRACTICE11
{

public static void main(String[] args) throws Exception
{

Scanner scan = new Scanner(System.in);

System.out.print(\"Enter your age: \");
int age = scan.nextInt();

if(age > 50)
System.out.print(\"You are older than 50\ \");
else if(age == 45 || age == 50)
System.out.print(\"You are either 45 OR 50\ \");
else if(age >= 19 && age <= 39)
System.out.print(\"You age is between 19 and 39\ \");
else if(age <= 18)
System.out.print(\"You are 18 years or younger\ \");
}
}

/*
output:

Enter your age: 34
You age is between 19 and 39

Enter your age: 11
You are 18 years or younger

Enter your age: 66
You are older than 50

Enter your age: 45
You are either 45 OR 50

*/

 Write a program that prompts the user to enter his age. Write the statements needed to display the following messages based on the entered value: \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site