Advertisement
kallyy7

Untitled

Feb 28th, 2018
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class JuiceDiet06 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int r = Integer.parseInt(scanner.nextLine());
  7.         int s = Integer.parseInt(scanner.nextLine());
  8.         int c = Integer.parseInt(scanner.nextLine());
  9.         int juiceMax = Integer.parseInt(scanner.nextLine());
  10.         double max = 0;
  11.         int maxRasp = 0;
  12.         int maxStraw = 0;
  13.         int maxCherries = 0;
  14.  
  15.         for (int i = 0; i <= r; i++) {
  16.             for (int j = 0; j <= s; j++) {
  17.                 for (int k = 0; k <= c; k++) {
  18.                      double cherries = 15 * k;
  19.                      double strawberries = 7.5 * j;
  20.                      double raspberries = 4.5 * i;
  21.                      double juiceCurrent = cherries + strawberries + raspberries;
  22.                      if (juiceCurrent <= juiceMax)
  23.                         {
  24.                             if (juiceCurrent > max)
  25.                             {
  26.                                 maxRasp = i;
  27.                                 maxStraw = j;
  28.                                 maxCherries = k;
  29.                                 max = juiceCurrent;
  30.                             }
  31.                         }
  32.                     if (juiceCurrent == juiceMax - 1 || juiceCurrent == juiceMax) {
  33.                         if (cherries > strawberries && cherries > raspberries || strawberries > raspberries){
  34.                             System.out.printf("%s Raspberries, %s Strawberries, %s Cherries. Juice: %.0f ml.", i, j, k, juiceCurrent);
  35.                         return;
  36.                         }
  37.                         else{
  38.                         System.out.printf("%s Raspberries, %s Strawberries, %s Cherries. Juice: %.0f ml.", i, j, k, juiceCurrent);
  39.                         return;
  40.                         }
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.         System.out.printf("%s Raspberries, %s Strawberries, %s Cherries. Juice: %s ml.", maxRasp, maxStraw, maxCherries, max);
  46.                        
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement