Skip to content

Instantly share code, notes, and snippets.

@joshz
Created June 8, 2011 16:45
Show Gist options
  • Save joshz/1014800 to your computer and use it in GitHub Desktop.
Save joshz/1014800 to your computer and use it in GitHub Desktop.
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