Expand|Select|Wrap|Line Numbers
- /////////////////////////////////
- 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.