In this tutorial, We are going to learn a python program to convert Celsius into Fahrenheit. This program will be simple because we will use just a given formula of Celsius to Fahrenheit conversion. We have to Just apply this conversion formula in java programming.
How our Program will behave?
• Java program will take a temperature value from user in Celsius as a input.
• We will apply Celsius to Fahrenheit conversion formula which is (Celsius * 9 / 5)+32.
• This calculation result will be temperature in Fahrenheit.
Program : Convert Celsius into Fahrenheit
import java.util.*;
public class Main
{
public static void main(String[] args) {
float celsius, fahrenheit;
System.out.println("Program to convert Celsius to Fahrenheit" );
Scanner sc = new Scanner(System.in);
System.out.println("Please give the Celsius Temperature");
celsius= sc.nextFloat();
fahrenheit = (celsius * 9 / 5) + 32;
System.out.printf("Fahrenheit = %.2f",fahrenheit);
}
}
Output
Program to convert Celsius to Fahrenheit
Please give the Celsius Temperature
36
Fahrenheit = 96.80
Explanation
For the input Celsius temperature 37.
Fahrenheit temperature = (37 *9/5) + 32 = 98.60.
The above Java program helps users convert temperatures from Celsius to Fahrenheit. First, it tells the user that it is a temperature conversion program. It then asks the user to input a temperature in Celsius. Once the user types the Celsius temperature and enters it, the program calculates the Fahrenheit equivalent. The formula used multiplies the Celsius temperature by 9, divides it by 5, and then adds 32 to get the result in Fahrenheit.
Finally, the program displays the Fahrenheit temperature, rounding it to two decimal places for clarity. This makes it easy for anyone to convert temperatures from Celsius to Fahrenheit accurately.
I hope above Celsius to Fahrenheit Java program is clear to you.
Happy Coding!!