Java Arithmetic Operator convert celsius to fahrenheit

Question

We would like to convert celsius to fahrenheit using double type:

Write a program that reads a Celsius degree in a double value from the console.

Convert it to Fahrenheit and displays the result.

The formula for the conversion is as follows:

fahrenheit = (9 / 5) * celsius + 32
import java.util.Scanner;

public class Main {

  public static void main(String[] Strings) {

    Scanner input = new Scanner(System.in);

    System.out.print("Enter a degree in Celsius: ");
    double celsius = input.nextDouble();

    //your code here
    /*from  w  ww. java 2 s . co m*/
    System.out.println(celsius + " degree Celsius is equal to " + fahrenheit + " in Fahrenheit");
  }
}


import java.util.Scanner;

public class Main {

  public static void main(String[] Strings) {

    Scanner input = new Scanner(System.in);

    System.out.print("Enter a degree in Celsius: ");
    double celsius = input.nextDouble();

    double fahrenheit = (9.0 / 5.0) * celsius + 32.0;
    System.out.println(celsius + " degree Celsius is equal to " + fahrenheit + " in Fahrenheit");
  }
}



PreviousNext

Related