gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Write the following code in Java: Make a program which displays a different message…
- User
Write the following code in Java: Make a program which displays a different message depending on the age given. Here are the possible responses:
age is less than 16, say "You can't drive." age is less than 18, say "You can't vote." age is less than 25, say "You can't rent a car." age is 25 or over, say "You can do anything that's legal."
- Assistantjava
import java.util.Scanner; public class AgeMessage { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your age: "); int age = scanner.nextInt(); if (age < 16) { System.out.println("You can't drive."); } else if (age < 18) { System.out.println("You can't vote."); } else if (age < 25) { System.out.println("You can't rent a car."); } else { System.out.println("You can do anything that's legal."); } scanner.close(); } }