Table of Contents
Convert Fahrenheit into Celsius in Java
In this article, we will discuss the concept of “Convert Fahrenheit into Celsius in Java”
In this post, we will learn how to write a program to convert Fahrenheit into Celsius in Java Programming language.
Here, we have four methods and explain how to calculate Celsius using the given Fahrenheit value and display the result on the screen in Java programming language.
Code to Alter Fahrenheit into Celsius
Convert Fahrenheit into Celsius -#1
In this program, the user declares two variables celsius and Fahrenheit, and initiates the value as 32.0 to Fahrenheit. Then the scientific equation will convert from Fahrenheit into Celsius in the Java programming language.
Program 1
public class Fahrenheit_To_Celsius { public static void main (String args[]){ //declaring variables double fahre=32,cels; cels=((fahre-32)*5/9); //Calculate Celsius value System.out.print("Temperature in Celsius:"+cels); } }
When the above code is executed, it produces the following result
Temperature in Celsius:0.0
Convert Fahrenheit into Celsius -Entered by the user-#2
In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for the value from the user to Fahrenheit then the given input will convert from Fahrenheit into Celsius in the Java programming language using the scientific equation.
Program 2
import java.util.Scanner; public class Fahrenheit_To_Celsius { public static void main (String args[]){ //declaring variables double fahre,cels; Scanner input=new Scanner(System.in); System.out.print("Enter the value to Fahrenheit: "); fahre=input.nextDouble(); cels=((212fahre-32)*5/9); //Calculate Celsius value System.out.print("Temperature in Celsius:"+cels); } }
When the above code is executed, it produces the following result
Enter the value to Fahrenheit: 212 Temperature in Celsius:100.0
Convert Fahrenheit into Celsius Using function – #3
In this program, the user declares a variable as a parameter for Fahrenheit(f) in the user-defined method. When the user runs the program (when calling the method), the value of Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.
Program 3
//Java program to Solution to Convert Fahrenheit into Celsius //using method public class Fahrenheit_To_Celsius1 { double fahre_tO_cels(double fahrenheit){ return ((fahrenheit-32)*5/9); } public static void main (String args[]){ //declaring variable double fahren=50; Fahrenheit_To_Celsius1 res = new Fahrenheit_To_Celsius1(); double result=res.fahre_tO_cels(fahren); System.out.println("Temperature in Farhenheit:"+result); } }
When the above code is executed, it produces the following result
Temperature in Farhenheit:10.0
Convert Fahrenheit into Celsius Using the function -Entered by user #4
In this program, the user declares a double variable as a parameter for Fahrenheit(F) in the user-defined method. When the user runs the program (when calling the method), the user is asked to enter the value of Fahrenheit and then the value of Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.
Program 4
//Java program to Solution to Convert Celsius into Fahrenheit //using method import java.util.Scanner; public class Fahrenheit_To_Celsius2 { double fahre_tO_cels(double fahrenheit){ return ((fahrenheit-32)*5/9); } public static void main (String args[]){ Fahrenheit_To_Celsius2 res=new Fahrenheit_To_Celsius2(); //declaring variables double fahre; Scanner input=new Scanner(System.in); System.out.print("Enter the value to Fahrenheit: "); fahre=input.nextDouble(); double result=res.fahre_tO_cels(fahre); System.out.print("Temperature in Farhenheit:"+result); } }
When the above code is executed, it produces the following result
Enter the value to Fahrenheit: 212 Temperature in Farhenheit:100.0
Similar post
Celsius into Fahrenheit in the C program
Fahrenheit into Celsius in C program
Celsius into Fahrenheit in C++ program
Fahrenheit into Celsius in C++ program
Celsius into Fahrenheit in the C# program
Fahrenheit into Celsius in C# program
Alter Celsius into Fahrenheit in Python
Alter Fahrenheit into Celsius in Python
Alter Celsius into Fahrenheit in PHP
Alter Fahrenheit into Celsius in PHP
Alter Celsius into Fahrenheit in JavaScript
Alter Fahrenheit into Celsius in JavaScript