Advertisement
Spocoman

Gold Mine

Sep 7th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int locations = Integer.parseInt(scanner.nextLine());
  7.  
  8.         for (int i = 0; i < locations; i++) {
  9.             double averageGold = Double.parseDouble(scanner.nextLine()),
  10.                     gold, goldSum = 0;
  11.             int dayDigging = Integer.parseInt(scanner.nextLine());
  12.             for (int j = 0; j < dayDigging; j++) {
  13.                 gold = Double.parseDouble(scanner.nextLine());
  14.                 goldSum += gold;
  15.             }
  16.  
  17.             if (goldSum / dayDigging >= averageGold) {
  18.                 System.out.printf("Good job! Average gold per day: %.2f.\n", goldSum / dayDigging);
  19.             } else {
  20.                 System.out.printf("You need %.2f gold.\n", averageGold - (goldSum / dayDigging));
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement