How to convert Fahrenheit to Celsius

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dfluker
    New Member
    • Feb 2010
    • 10

    How to convert Fahrenheit to Celsius

    The Java code for this temperature conversion from Fahrenheit to Celsius is given below. the code starts by asking the user to enter a temperature in Fahrenheit scale and then displays the equivalent Celsius Temperature.



    Code:
    /////////////////////////////////
    
    package developer;
    
    
    
    import java.util.Scanner;
    
    
    
    public class FahrenheitToCelsius {
    
    
    
        public static void main(String[] args) {
    
            System.out.println("Enter a temperature in Fahrenheit: ");
    
            Scanner scanFaren = new Scanner(System.in);
    
            double Celsius = 0;
    
           
    
            if(scanFaren.hasNextDouble())
    
            {
    
                Celsius = (scanFaren.nextDouble() - 32)*5/9;
    
            }
    
            System.out.println("The temperature in Celsius is: "+Celsius);
    
           
    
        }
    
    }
    
    /////////////////////////////////
    
    
    
    When this Java Code was executed on my JVM, then the output was as shown below.
    
    
    
    /////////////////////////////////
    
    Enter a temperature in Fahrenheit: 
    
    56
    
    The temperature in Celsius is: 13.333333333333334
    
    /////////////////////////////////

    Hope that the Java code provide for conversion from Fahrenheit to Celsius was useful to you all.
Working...