Site icon Codeforcoding

Program to convert Fahrenheit to Celsius using Java method

Program to convert Fahrenheit into Celsius using the Java method

In this tutorial, we will discuss the concept of the program to convert Fahrenheit into celsius using the Java method

In this post, we will learn how to write a program to convert Fahrenheit into Celsius using the scientific equation in Java programming language with an Example program.

Temperature and conversion

Conversion equation

Generally, We have known three types of temperature units Fahrenheit, Celsius, and Kelvin. In this article, we are discussing how to convert temperature units Fahrenheit into Celsius. Fahrenheit and Celsius are the measuring units in degrees as 0F and 0C  respectively.

Scientific equation Celsius = (Fahrenheit-32)*9/5

program to convert Fahrenheit into Celsius

Code to Fahrenheit into Celsius

 Fahrenheit into Celsius

In this program, the user declares a double variable as a parameter for Celsius in the user-defined method. When the user calls the method, the celsius value passes to the method as an argument.
Finally, the Celsius value is calculated using a scientific equation
and displays on the screen.

Program 1

class Fah_to_Cel_method{
    double con_Celsius(double f){
    
return ((f-32)*5/9);
}

public static void main(String args[]){
Fah_to_Cel_method res=new Fah_to_Cel_method();
double result=res.con_Celsius(32);
double result1=res.con_Celsius(212);
double result2=res.con_Celsius(140);
System.out.println( "celsius is =" +result);
System.out.println( "celsius is =" +result1);
System.out.println( "celsius is =" +result2);
}
}

When the above code is executed, it produces the following result

Celsius is =0.0;
Celsius is =100.0;
Celsius is =60.0;

 

Fahrenheit into Celsius – Entered by the user

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined method. When the user runs the program (calling the method), the program is asked for the value for Fahrenheit and stores the given value in the variable Fahrenheit as an argument for the method.
Finally, the Celsius value is calculated using scientific equations and displayed on the screen.

Program 2

import java.util.Scanner;
class Fah_to_Cel_method1{
    double con_Celsius(double f){
    
return ((f-32)*5/9);
}

public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a degree in Fahrenheit: ");
double fahrenheit=sc.nextDouble();

Fah_to_Cel_method1 res=new Fah_to_Cel_method1();
double result=res.con_Celsius(fahrenheit);
System.out.println( "Celsius is =" +result);

}
}

When the above code is executed, it produces the following result

Enter a degree in Fahrenheit:
212
Celsius is =100.0

 

Similar post

Code to convert Fahrenheit to Celsius using the Java

Code to convert Celsius to Fahrenheit using the Java

Java code to convert Fahrenheit to Celsius  using the method

Java code to convert Celsius to Fahrenheit using the method

Code to convert Fahrenheit to Celsius using the JavaScript

Code to convert Celsius to Fahrenheit using the JavaScript function

PHP code to convert Fahrenheit to Celsius  using the function

Python code to convert Celsius to Fahrenheit

Java Program: Convert Celsius into Fahrenheit  using method
C Program: Convert Celsius into Fahrenheit
Exit mobile version