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

Java switch case program

The document contains a Java program for a temperature converter that allows users to convert between Celsius and Fahrenheit. It prompts the user to choose a conversion type and then takes the corresponding temperature input to perform the calculation. The program uses a switch case structure to handle the user's choice and outputs the converted temperature or an error message for invalid input.

Uploaded by

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

Java switch case program

The document contains a Java program for a temperature converter that allows users to convert between Celsius and Fahrenheit. It prompts the user to choose a conversion type and then takes the corresponding temperature input to perform the calculation. The program uses a switch case structure to handle the user's choice and outputs the converted temperature or an error message for invalid input.

Uploaded by

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

Java switch case program:

import java.util.Scanner;

public class TemperatureConverter {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("Choose conversion:");
System.out.println("1. Celsius to Fahrenheit");
System.out.println("2. Fahrenheit to Celsius");
int choice = input.nextInt();

switch (choice) {
case 1:
System.out.print("Enter temperature in Celsius: ");
double celsius = input.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 = input.nextDouble();
celsius = (fahrenheit - 32) * 5 / 9;
System.out.println("Temperature in Celsius: " + celsius);
break;

default:
System.out.println("Invalid choice.");
}
}
}

You might also like