Created
June 8, 2011 16:45
-
-
Save joshz/1014800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.text.DecimalFormat; | |
public class Temperature | |
{ | |
public static void main (String [] args) | |
{ | |
Scanner keyboard = new Scanner(System.in); | |
double celsius; | |
System.out.print("Enter a degree in Celsius: "); | |
celsius = keyboard.nextDouble(); | |
double fahrenheit = 9.0/5*celsius + 32; | |
// you can use this | |
// 45.0C -> 113.000F | |
// 65.4578C -> 149.842F | |
DecimalFormat df = new DecimalFormat("#.000"); | |
System.out.print(celsius + " degree Celsius is " + df.format(fahrenheit) + " degrees Fahrenheit\n"); | |
// or this | |
// 45.0C -> 113.0F | |
// 65.4578C -> 149.842F | |
System.out.print(celsius + " degree Celsius is " + Math.floor(fahrenheit*1000 + 0.5)/1000 + " degrees Fahrenheit "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment