Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package worldtemperaturetablecalculator;
- import java.util.Scanner;
- public class WorldTemperatureTableCalculator {
- public static void main(String[] args) {
- // The multiplier used in conversion formula
- final double Multiplier = 1.8;
- // The offset used in conversion formula
- final double Offset = 32;
- // Scanner to obtain user inputs
- Scanner Inputs = new Scanner(System.in);
- // Ask the user what city
- System.out.println("What city do you live in?");
- // String to store city information
- String City = Inputs.nextLine();
- // Asks the user what is the temperature in Celsius there
- System.out.println("Enter a starting temperature in Celsius:");
- // double to store initial degrees Celsius
- int Celsius = (int)Inputs.nextDouble();
- // Closes the scanner
- Inputs.close();
- // Output the resulting conversion along with city
- System.out.printf("Temperature Conversion Table for %s:%n%n" +
- "%-18sFahrenheit%n" , City, "Celsius");
- // Integer to specify limit of loop (counter)
- int Range = Celsius + 20;
- // Double to store resulting Fahrenheit conversions
- double Fahrenheit;
- // Convert and print 20 following temperatures (inclusive)
- for (int i = Celsius; i < Range; i++)
- {
- // Do Celsius to Fahrenheith convertion for current i
- Fahrenheit = (Multiplier * i) + Offset;
- // Print Celsius as integer and Fahrenheit to 1 decimal point
- System.out.printf("%-18d%.1f%n", i, Fahrenheit);
- }
- } // End of main()
- } // End of WorldTemperatureTableCalculator class
Advertisement
Add Comment
Please, Sign In to add comment