veronikaaa86

06.JuiceDiet

Feb 24th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class Task6_JuiceDiet {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int raspberries = Integer.parseInt(scanner.nextLine());
  8.         int strawberries = Integer.parseInt(scanner.nextLine());
  9.         int cherries = Integer.parseInt(scanner.nextLine());
  10.         int juice = Integer.parseInt(scanner.nextLine());
  11.         DecimalFormat decimalFormat = new DecimalFormat("0.#");
  12.         String result = "";
  13.         double maxAlcohol = -1;
  14.  
  15.         for (int i = cherries; i >= 0; i--) {
  16.             for (int j = strawberries; j >= 0; j--) {
  17.                 for (int k = raspberries; k >= 0; k--) {
  18.                     double currJuice = k * 4.5 + j * 7.5 + i * 15;
  19.                     if (currJuice <= juice && maxAlcohol < currJuice) {
  20.                         maxAlcohol = currJuice;
  21.                         result = k + " Raspberries, " +j + " Strawberries, " + i + " Cherries. Juice: " + decimalFormat.format(maxAlcohol) + " ml.";
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.  
  27.         System.out.println(result);
  28.     }
  29. }
Add Comment
Please, Sign In to add comment