Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Description of Program example: Tool to Determine [ . . . ]
- //Name
- //date
- //special requirements:
- import java.util.Scanner;
- public class Temperature {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double celsius, fahrenheit;
- double input_total = 0;
- double fahrenheit_total = 0, celcius_total = 0;
- double fahrenheit_average, celcius_average;
- do {
- System.out.print("Enter the Temperature in Centigrade or <= -100.0 to quit: ");
- celsius = scan.nextInt();
- if (celsius > -100)
- {
- fahrenheit = ((9.0/5.0) * celsius + 32.0);
- input_total ++;
- fahrenheit_total = fahrenheit_total + fahrenheit;
- celcius_total = celcius_total + celsius;
- System.out.println("Temperature: F" + " (" + fahrenheit + ") " + "C" + " (" + celsius + ")");
- }
- }
- while (celsius > -100);
- if (input_total > 0)
- {
- fahrenheit_average = (fahrenheit_total / input_total);
- celcius_average = (celcius_total / input_total);
- }
- else
- {
- fahrenheit_average = 0;
- celcius_average = 0;
- }
- System.out.printf("Average: Fahrenheit:(%.2f)\n", fahrenheit_average);
- System.out.printf("Average: Centigrade:(%.2f)\n", celcius_average);
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement