variables.java
[edit | edit source]/** * This program converts a Fahrenheit temperature to Celsius. * * Input: * Fahrenheit temperature * * Output: * Fahrenheit temperature * Celsius temperature * * Example: * Enter Fahrenheit temperature: * 100 * 100.0° Fahrenheit is 37.8° Celsius * * TODO: * * Functions will be added in a future release. * * References: * * http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html * * https://www.w3resource.com/slides/java-coding-style-guide.php * * http://www.mathsisfun.com/temperature-conversion.html */ importjava.util.Scanner; class Main{ publicstaticfinalintTEMPERATURE_DIFFERENCE=32; publicstaticfinaldoubleTEMPERATURE_RATIO=5.0/9; publicstaticvoidmain(String[]args){ System.out.println("Enter Fahrenheit temperature:"); Scannerscanner=newScanner(System.in); doublefahrenheit; fahrenheit=scanner.nextDouble(); doublecelsius; celsius=(fahrenheit-TEMPERATURE_DIFFERENCE)*TEMPERATURE_RATIO; System.out.println(String.format( "%1$.1f° Fahrenheit is %2$.1f° Celsius", fahrenheit, celsius)); } }
Try It
[edit | edit source]Copy and paste the code above into one of the following free online development environments or use your own Java compiler / interpreter / IDE.
