temperature conversion

Convert Fahrenheit into Celsius in Java

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

 

 

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.