deyanivanov966

EXAM 25.10 // 06. Gold Mine

Oct 25th, 2020 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GoldMine {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int locations = Integer.parseInt(scanner.nextLine());
  8.  
  9.         for (int i = 1; i <= locations ; i++) {
  10.  
  11.             double expected = Double.parseDouble(scanner.nextLine());
  12.             int days = Integer.parseInt(scanner.nextLine());
  13.  
  14.             int digs = 0;
  15.             double quantity = 0;
  16.  
  17.             for (int j = 1; j <= days ; j++) {
  18.                 digs = days;
  19.                 double gold = Double.parseDouble(scanner.nextLine());
  20.                 quantity += gold;
  21.  
  22.             }
  23.             double average = quantity / days;
  24.             if (average >= expected) {
  25.                 System.out.printf("Good job! Average gold per day: %.2f.%n", average);
  26.             } else {
  27.                 System.out.printf("You need %.2f gold.%n", expected - average);
  28.             }
  29.  
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment