// CelsiusBetter.java Copyright (c) 2006 Kari Laitinen // http://www.naturalprogramming.com // 2006-02-15 File created. // 2006-02-15 Last modification. // Solution to Exercise 7-8. import java.util.* ; class CelsiusBetter { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; int[] array_of_degrees_fahrenheit = { 32, 34, 36, 37, 39, 41, 43, 45, 46, 48, 50, 52, 54, 55, 57, 59, 61, 63, 64, 66, 68, 70, 72, 73, 75, 77, 79, 81, 82, 84, 86, 88, 90, 91, 93, 95, 97, 99, 100, 102 } ; int[] small_degrees_fahrenheit = { 32, 30, 28, 27, 25, 23, 21, 19, 18, 16, 14, 12, 10, 9, 7, 5, 3, 1, 0, -2, -4, -6, -8, -9,-11,-13,-14,-16,-18,-20, -22,-24,-26, -27,-29,-31,-33,-35,-36,-38, -40 } ; System.out.print( "\n This program converts temperatures given in" + "\n degrees Celsius to degrees Fahrenheit." + "\n Please, give a temperature in degrees Celsius: " ) ; int degrees_celsius = keyboard.nextInt( ) ; if ( degrees_celsius >= 0 ) { System.out.print( "\n " + degrees_celsius + " degrees Celsius is " + array_of_degrees_fahrenheit[ degrees_celsius ] + " degrees Fahrenheit. \n" ) ; } else { System.out.print( "\n " + degrees_celsius + " degrees Celsius is " + small_degrees_fahrenheit[ - degrees_celsius ] + " degrees Fahrenheit. \n" ) ; } } }