Exercise
Age
Objetive
Write a java program to ask the user for their age (e.g. 20) and respond with something like "You look younger than 20" (the age entered by the user should be displayed in place of "20").
Example Code
// Importing the Scanner class to handle input from the useimport java.util.Scanner; // Import Scanner class for input
public class Program {
// Main entry point of the program
public static void main(String[] args) {
// Create a scanner object to read user input
Scanner scanner = new Scanner(System.in);
// Ask the user to input their age
System.out.print("Please enter your age: ");
// Read the user's input as an integer
int age = scanner.nextInt();
// Respond with a message based on the user's age
System.out.println("You look younger than " + age);
// Close the scanner to free up resources
scanner.close();
}
}