Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

Convert Fahrenheit into Celsius in Java

Posted on June 7, 2023June 10, 2023

Table of Contents

  • Convert Fahrenheit into Celsius in Java
    • Code to Alter Fahrenheit into Celsius
      • Convert Fahrenheit into Celsius  -#1
      • Convert Fahrenheit into Celsius  -Entered by the user-#2
      • Convert Fahrenheit into Celsius Using function – #3
      • Convert Fahrenheit into Celsius Using the function -Entered by user #4

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

 

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes