- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Time Conversion Table Using Menu
40. Write a menu driven program to display the following menu:
Conversion Table
============
- Milliseconds to Seconds
- Milliseconds to Minutes
- Seconds to Milliseconds
- Seconds to Minutes
- Minutes to Milliseconds
- Minutes to Seconds
For an incorrect choice, display an appropriate error message.
Hint: 1 second = 1000 milliseconds
import java.util.Scanner;
public class TimeConversion {
public static void main(String[] args) {
// Title
System.out.println("CONVERSION TABLE");
System.out.println("================");
System.out.println("1. Milliseconds to Seconds");
System.out.println("2. Milliseconds to Minutes");
System.out.println("3. Seconds to Milliseconds");
System.out.println("4. Seconds to Minutes");
System.out.println("5. Minutes to Milliseconds");
System.out.println("6. Minutes to Seconds");
Scanner sc = new Scanner(System.in);
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
double value, result;
switch (choice) {
case 1:
System.out.print("Enter milliseconds: ");
value = sc.nextDouble();
result = value / 1000;
System.out.println("Seconds = " + result);
break;
case 2:
System.out.print("Enter milliseconds: ");
value = sc.nextDouble();
result = value / (1000 * 60);
System.out.println("Minutes = " + result);
break;
case 3:
System.out.print("Enter seconds: ");
value = sc.nextDouble();
result = value * 1000;
System.out.println("Milliseconds = " + result);
break;
case 4:
System.out.print("Enter seconds: ");
value = sc.nextDouble();
result = value / 60;
System.out.println("Minutes = " + result);
break;
case 5:
System.out.print("Enter minutes: ");
value = sc.nextDouble();
result = value * 60 * 1000;
System.out.println("Milliseconds = " + result);
break;
case 6:
System.out.print("Enter minutes: ");
value = sc.nextDouble();
result = value * 60;
System.out.println("Seconds = " + result);
break;
default:
System.out.println("Invalid choice! Please select between 1 and 6.");
}
sc.close();
}
}
Output
Sample Output CONVERSION TABLE ================ 1. Milliseconds to Seconds 2. Milliseconds to Minutes 3. Seconds to Milliseconds 4. Seconds to Minutes 5. Minutes to Milliseconds 6. Minutes to Seconds Enter your choice: 1 Enter milliseconds: 5000 Seconds = 5.0
📝 Explanation
- Menu is displayed using print statements
- User selects conversion type
- switch-case performs the selected conversion
- Correct formula is applied based on the choice
- An error message is shown for an invalid choice
