Computer Science, asked by prajwalvasista8, 1 month ago

Write a java program to convert the given temperature from centigrade

to farenheit and vice versa.

Choice 1, convert centigrade to Fahrenheit

F= (C *9/5) + 32

Choice= 2, convert Farenheit to centigrade

C= (F-32) * 5/9​

Answers

Answered by udayagrawal49
2

Answer:

The required Java program to convert the given temperature from Centigrade to Farenheit is :-

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 try{

  System.out.println("Enter the temperature(in °C)");

  Scanner scan = new Scanner(System.in);

  double c = scan.nextDouble();

  scan.close();

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

  System.out.println(c+" °C in Fahrenheit is "+f+" F");

 }

 catch (Exception e) {

  System.out.println("Some error occured");

 }

}

}

The required Java program to convert the given temperature from Farenheit to Centigrade is :-

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 try{

  System.out.println("Enter the temperature(in F)");

  Scanner scan = new Scanner(System.in);

  double f = scan.nextDouble();

  scan.close();

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

  System.out.println(f+" F in Centigrade is "+c+" °C");

 }

 catch (Exception e) {

  System.out.println("Some error occured");

 }

}

}

Similar questions