desislava_topuzakova

06. Gold Mine

Nov 3rd, 2021
1,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package EXAMS;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class goldMine {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int location = Integer.parseInt(scanner.nextLine());
  10.         for (int i = 0; i < location; i++) {
  11.             double avrExtraction = Double.parseDouble(scanner.nextLine());
  12.             int days = Integer.parseInt(scanner.nextLine());
  13.             double sumExtraction = 0.0;
  14.             for (int j = 0; j < days; j++) {
  15.                 double extraction = Double.parseDouble(scanner.nextLine());
  16.                 sumExtraction += extraction;
  17.             }
  18.             double average = sumExtraction /days;
  19.             if(average >= avrExtraction) {
  20.                 System.out.printf("Good job! Average gold per day: %.2f.\n",average);
  21.             }else {
  22.                 System.out.printf("You need %.2f gold.\n", avrExtraction - average);
  23.             }
  24.         }
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment