Respuesta :
Answer:
import java.util.Scanner;
public class TimeConversion
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("1. Hours to minutes\n2. Days to hours\n3. Minutes to hours\n4. Hours to days\n");
System.out.print("Enter your choice:");
int choice = input.nextInt();
switch(choice) {
case 1:
System.out.print("Enter the number of hours:");
int hour = input.nextInt();
System.out.println("There are "+ hour*60 + " minutes in " + hour + " hours");
break;
case 2:
System.out.print("Enter the number of days:");
int day = input.nextInt();
System.out.println("There are "+ day*24 + " hours in " + day + " days");
break;
case 3:
System.out.print("Enter the number of minutes:");
int minute = input.nextInt();
System.out.println("There are "+ minute/60 + " hours in " + minute + " minutes");
break;
case 4:
System.out.print("Enter the number of hours:");
int h = input.nextInt();
System.out.println("There are "+ h/24 + " days in " + h + " hours");
break;
default:
System.out.println("Invalid Input!");
}
}
}
Explanation:
- Print the menu
- Ask the user to choose one of the options
- Depending on the choice, use switch-case statement to calculate and print required conversion
- Print an error message if the user enters a number that is not in the menu