Celsius into Fahrenheit
Table of Contents
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
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
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
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
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
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.