temperature conversion

The Solution to Convert Celsius into Fahrenheit in Java

The solution to Convert Celsius into Fahrenheit in Java

In this article, we will discuss the concept of “The Solution to Convert Celsius into Fahrenheit in Java”

In this post, we will learn how to write a program to convert Celsius into Fahrenheit and display the result on the screen in Java language. Here, we have four methods and explain how to calculate Fahrenheit using the given Celsius value  in the Java programming language

Code to Celsius into Fahrenheit

Convert Celsius into Fahrenheit -Solution 1

In this program, the user declares two double variables as Celsius and Fahrenheit and initiates the value as 50.0 to the variable Celsius. After that, It will convert from Celsius into Fahrenheit in Java using The scientific equation.

Program 1

//Java program to Solution to Convert Celsius into Fahrenheit 
public class Celsius_To_Fahrenheit { 
public static void main (String args[]){ 
//declaring variables 
double fahre,cels=50; 
fahre=(cels*9/5)+32; 
//Calculate Fahrenheit value 
System.out.print("Temperature in Farhenheit:"+fahre); }
 }

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

Temperature in Farhenheit:122.0

 

Convert Celsius into Fahrenheit -Entered by the user-Solution 2

In this program, the user declares two double variables as Celsius and Fahrenheit. The program asks for input from the user to Celsius then the given value will be converted from Celsius into Fahrenheit in the Java programming language using the scientific equation.

Program 2

//Java program to Solution to Convert Celsius into Fahrenheit
import java.util.Scanner;
public class Celsius_To_Fahrenheit
{
public static void main (String args[]){
//declaring variables
double fahre,cels; 
Scanner input=new Scanner(System.in);

System.out.print("Input value to Celsius: 1");
cels=input.nextDouble();
fahre=(cels*9/5)+32;
//Calculate Fahrenheit value

  System.out.print("Temperature in Farhenheit:"+fahre);

}
}

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

Input value to Celsius: 100
Temperature in Farhenheit:212.0

 

Convert Celsius into Fahrenheit Using Method- Solution 3

In this program, the user declares a double variable as a parameter for Celsius(celsius) in the user-defined Method. When the user runs the program (when calling the method), the value for Celsius passes as an argument to the Method.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation in the Java programming language.

Program 3

//Java program to Solution to Convert Celsius into Fahrenheit
//using method
public class Celsius_To_Fahrenheit
{
  double cels_tO_fahre(double celsius){
  return (celsius*9/5)+32;
}
public static void main (String args[]){
//declaring variables
Celsius_To_Fahrenheit res = new Celsius_To_Fahrenheit();

double result=res.cels_tO_fahre(50);
double result1=res.cels_tO_fahre(100);
double result2=res.cels_tO_fahre(00);

  System.out.println("Temperature in Farhenheit:"+result);
  System.out.println("Temperature in Farhenheit:"+result1);
  System.out.print("Temperature in Farhenheit:"+result2);

}
}

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

Temperature in Farhenheit:122.0
Temperature in Farhenheit:212.0
Temperature in Farhenheit:32.0

 

Convert Celsius into Fahrenheit Using method-Entered by the user- Solution 4

In this program, the user declares a double variable as a parameter for Celsius(celsius) in the user-defined method. When the user runs the program (when calling the Method), The program asks for input from the user for Celsius and the value for Celsius passes as an argument to the function through the variable.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation in the Java programming language.

//Java program to Solution to Convert Celsius into Fahrenheit
//using method
import java.util.Scanner;
 public class Celsius_To_Fahrenheit
{
  double cels_tO_fahre(double celsius){
  return (celsius*9/5)+32;
}

public static void main (String args[]){
    Celsius_To_Fahrenheit res=new Celsius_To_Fahrenheit();
//declaring variables
double cels; 
Scanner input=new Scanner(System.in);

System.out.print("Enter the value to Celsius: ");
cels=input.nextDouble();
double result=res.cels_tO_fahre(cels);

  System.out.print("Temperature in Farhenheit:"+result);

}
}

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

Enter the value to Celsius: 100
Temperature in Farhenheit:212.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

Convert Celsius into Fahrenheit in Python

Convert Fahrenheit into Celsius in Python

Convert Celsius into Fahrenheit in PHP

Convert Fahrenheit into Celsius in PHP

Convert Celsius into Fahrenheit in JavaScript

Convert Fahrenheit into Celsius in JavaScript

 

 

 

Karmehavannan

Recent Posts

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,…

11 months 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…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

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

11 months 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…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.