0% found this document useful (0 votes)
7 views

7 B

Uploaded by

Dhruvin Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

7 B

Uploaded by

Dhruvin Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class TemperatureConverter {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("Temperature Conversion Menu:");
System.out.println("1. Convert Celsius to Fahrenheit");
System.out.println("2. Convert Fahrenheit to Celsius");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();

switch (choice) {
case 1:
System.out.print("Enter temperature in Celsius: ");
double celsius = scanner.nextDouble();
double fahrenheit = (celsius * 9/5) + 32;
System.out.println("Temperature in Fahrenheit: " +
fahrenheit);
break;
case 2:
System.out.print("Enter temperature in Fahrenheit:
");
fahrenheit = scanner.nextDouble();
celsius = (fahrenheit - 32) * 5/9;
System.out.println("Temperature in Celsius: " +
celsius);
break;
case 3:
System.out.println("Exiting program.");
break;
default:
System.out.println("Invalid choice. Please select a
valid option.");
}
System.out.println(); // Blank line for spacing
} while (choice != 3);

scanner.close();
}
}

You might also like