Computer Science, asked by akshaymahesh1512, 4 months ago

write a menu driven program to convert the temperature to celcius or to farenheit in java

Answers

Answered by prem00016
2

In this program celsius(double f) is the method which calculates the Celsius temperature to the given Fahrenheit temperature using the formula (f-32)*5/9.

Explanation:

e.g .celsius= 12

fahrenheit= ((celsius*9)/5)+32

print("Temperature in Fahrenheit is: ");

print(fahrenheit);

Answered by BrainlyProgrammer
66

Answer:-

//Menu-driven program to convert temperature to degree celcius or degree Fahrenheit

package Programmer;

import java.util.Scanner;

public class Tempconverter {

public static void main (String ar []){

Scanner sc=new Scanner (System.in);

System.out.println("Enter your choice:\n1. Celcius to Fahrenheit\n2.Fahreheit to celcius");

int ch=sc.nextInt();

double c,f;

switch (ch){

case 1:

System.out.println("Enter temperature in Celcius");

c=sc.nextInt();

f=((9*c)/5)+32;

System.out.println("Converted Temperature:"+f);

break;

case 2:

System.out.println("Enter temperature in Fahrenheit");

f=sc.nextInt();

c=5*(f-32)/9;

System.out.println("Converted Temperature:" +c);

break;

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

}

}

}

_

Variable Description:-

  • c:- to store Temperature in celcius
  • f:- to store temperature in Fahrenheit
  • ch:- choice variable .. to accept user's choice

_

•Output attached

_______

Learn more:-

  • Formula to convert celcius to Fahrenheit

 \:  \:  \:  \:  \:  \:  \:  \:  \:  \:  \:  \:  \:  \boxed{ \bold{ \large \sf C=5  \times  \frac{F - 32}{9}}}

  • Formula to convert Fahrenheit to celcius

 \:  \:  \:  \:  \:  \:  \:  \:  \:  \:  \boxed{ \bold{ \large \sf F =  \frac{9 \times C}{5} + 32}}

Attachments:
Similar questions