Celsius into Fahrenheit
Table of Contents
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.
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
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
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
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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.