Advertisement
Guest User

Temperature

a guest
Feb 16th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Temperature {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.         double totalF = 0, totalC = 0, count = 0, c, f;
  8.         while (true) {
  9.             System.out.print("Enter Temp in Centigrade or <= -100.0 to quit: ");
  10.             c = in.nextDouble();
  11.             if (c <= -100)
  12.                 break;
  13.             f = (c * 1.8) + 32;
  14.             totalC += c;
  15.             totalF += f;
  16.             System.out.println("Temperature: F(" + f + ") C(" + c + ")");
  17.             ++count;
  18.         }
  19.         System.out.println("\nAverage: Centigrade(" + (totalC / count) + ") Average: Fahrenheit(" + (totalF / count) + ")");
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement