desislava_topuzakova

Juice Diet 07.01.2018

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