Home Lifestyle Java Program to Convert Celsius to Fahrenheit (updated)

Java Program to Convert Celsius to Fahrenheit (updated)

134
0

Java Program to Convert Celsius to Fahrenheit (updated) – Conversion from Celsius to Fahrenheit and from Fahrenheit to Celsius has an important role in the conversion of units system. In this post, we will develop a Java program to convert Celsius to Fahrenheit.

The formula used to convert from Celsius to Fahrenheit is given as,

⁰F= (⁰C * 9/5) + 32

<img decoding=

Java Program to Convert Celsius to Fahrenheit



import java.util.Scanner;

public class TemperatureConversion {
  // method to convert celsius to fahrenheit
  private static double tofahrenheit(double celsius){
     return ( celsius * (9.0/5.0) + 32 );
  }

  public static void main(String[] args) {

     // declare variables
     double celsius = 0.0;
     double fahrenheit = 0.0;

     // create Scanner class object to read input
     Scanner scan = new Scanner(System.in);

     // read input
     System.out.print("Enter Celsius value:: ");
     celsius = scan.nextDouble();

     // convert temperature
     fahrenheit = tofahrenheit(celsius);

     // display result
     System.out.println("Fahrenheit value = "
                         +fahrenheit);

     // close Scanner class object
     scan.close();
  }
}
The output for different test-cases:-

OUTPUT



Enter Celsius value:: 15
Fahrenheit value = 59.0

Types of Sorting Algorithms:

Additional Reading

READ MORE

If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.

Thank you 😊 Keep Learning !

Previous articleSum of Series Program in Java Language
Next articleProgram to Convert Fahrenheit to Celsius in Java Language (updated)

LEAVE A REPLY

Please enter your comment!
Please enter your name here