In java with output
Temperature-conversion program that gives the user the option of converting
Fahrenheit to Celsius or Celsius to Fahrenheit and depending upon user’s choice carries out the
conversion. [Formula: (9*Celsius)/5=(Fahrenheit-32)]
Answers
class CelsiustoFahrenheit
{
public static void main(String arg[])
{
double a,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Celsius temperature");
a=sc.nextDouble();
System.out.println("Fahrenheit temperature is = "+fahrenheit(a));
}
static double fahrenheit(double c)
{
return ((9*c)/5)+32;
}
}
Explanation:
PLEASE GIVE A BEAUTIFUL THANKS, I'LL GIVE YOU MORE ANSWERS IN ALL I.T RELATED QUESTIONS...
ALSO MARKED ME AS BRAINLIEST.
Answer: I have also added all possible outputs
import java.util.Scanner;
public class CelciusToFahrenheit{
public void main (){
Scanner sc = new Scanner(System.in);
System.out.println("Press 0 for Celcius to Fahrenheit and 1 for Vice-Versa");
double choice = sc.nextDouble();
if (choice == 0){
System.out.print("Enter the temperature in Celcius: ");
double tempC = sc.nextDouble();
double tempF = (tempC*1.8) + 32;
System.out.println("The temperature in Fahrenheit: " + tempF + "°F");}
if (choice == 1){
System.out.print("Enter the temperature in Fahrenheit: ");
double tempF = sc.nextDouble();
double tempC = (tempF - 32)/1.8;
System.out.println("The temperature in Celcius: " + tempC + "°C");}
if (choice != 0 && choice != 1)
System.out.println("Enter only 1 or 2 :(");
}
}
Output:
(i)
Press 0 for Celcius to Fahrenheit and 1 for Vice-Versa
0
Enter the temperature in Celcius: 37
The temperature in Fahrenheit: 98.60000000000001°F
(ii)
Press 0 for Celcius to Fahrenheit and 1 for Vice-Versa
123
Enter only 1 or 2 :(
(iii)
Press 0 for Celcius to Fahrenheit and 1 for Vice-Versa
1
Enter the temperature in Fahrenheit: 98.6
The temperature in Celcius: 36.99999999999999°C