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

The Solution to Convert Celsius into Fahrenheit in Java

Posted on June 7, 2023

Table of Contents

  • The solution to Convert Celsius into Fahrenheit in Java
    • Code to Celsius into Fahrenheit
      • Convert Celsius into Fahrenheit -Solution 1
      • Convert Celsius into Fahrenheit -Entered by the user-Solution 2
      • Convert Celsius into Fahrenheit Using Method- Solution 3
      • Convert Celsius into Fahrenheit Using method-Entered by the user- Solution 4

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

 

 

 

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