Java Fahrenheit to Celsius

Convert Fahrenheit to Celsius

To Convert Fahrenheit to Celsius:

  • Take the temperature in Fahrenheit subtract 32.
  • Divide by 1.8.
  • The result is degrees Celsius.

public class Main {
/*from   w w w.  ja v  a 2s  .c  om*/
  public static void main(String[] args) {
    for (int i=-40; i<=120; i+=10) {
      float c = (i-32)*(5f/9);
      System.out.println("fahrenheit "+i + " to celsius " + c);
    }
  }
}

The code above generates the following result.

To Convert Celsius to Fahrenheit

  • Take the temperature in Celsius and multiply 1.8.
  • Add 32 degrees.
  • The result is degrees Fahrenheit.

Next chapter...

What you will learn in the next chapter:

  1. What is Java Format Class
  2. Syntax for format method
  3. Note for format method
  4. Example - format method
Home »
  Java Tutorial »
    Java Langauge »
      Java Algorithms
Java Bubble sort
Java Binary Search
Java Insertion Sort
Java Selection sort
Java Shell sort
Java Heap Sort
Java Merge Sort
Java Quick Sort
Java Fibonacci
Java Hanoi puzzle
Java Fahrenheit to Celsius