fork download
  1. import java.util.Scanner;
  2.  
  3. class Q32835243
  4. {
  5. private static double farhenheitToCelsius(final double fahrenheit) {return (fahrenheit - 32) * 5 / 9;}
  6.  
  7. public static void main(final String[] args)
  8. {
  9. final Scanner keyboard = new Scanner(System.in);
  10.  
  11. System.out.print("Enter a temperature in Fahrenheit: ");
  12. if (keyboard.hasNextDouble())
  13. {
  14. final double fahrenheit = keyboard.nextDouble();
  15. final double celsius = farhenheitToCelsius(fahrenheit);
  16. System.out.format("The temperature in Celsius is: %8.4f%n", celsius);
  17. System.out.format("Fahrenheit\t Celsius%n");
  18.  
  19. for (int i = 0; i < 100; i += 10)
  20. {
  21. System.out.format("%8.4f\t%8.4f%n", fahrenheit + i, farhenheitToCelsius(fahrenheit + i));
  22. }
  23. }
  24. else
  25. {
  26. System.err.format("%s is not a double!%nPlease enter a double value.", keyboard.next());
  27. System.exit(1);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.17s 321280KB
stdin
90
stdout
Enter a temperature in Fahrenheit: The temperature in Celsius is:  32.2222
Fahrenheit	 Celsius
 90.0000	 32.2222
100.0000	 37.7778
110.0000	 43.3333
120.0000	 48.8889
130.0000	 54.4444
140.0000	 60.0000
150.0000	 65.5556
160.0000	 71.1111
170.0000	 76.6667
180.0000	 82.2222