Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. package juicediet;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class JuiceDiet {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         int r = Integer.parseInt(scanner.nextLine());
  12.         int s = Integer.parseInt(scanner.nextLine());
  13.         int c = Integer.parseInt(scanner.nextLine());
  14.         int maxJuice = Integer.parseInt(scanner.nextLine());
  15.  
  16.         double juice = 0;
  17.         int rasp = 0;
  18.         int str = 0;
  19.         int cher = 0;
  20.  
  21.         for (int k = 0; k <= c; k++) {
  22.             for (int j = 0; j <= s; j++) {
  23.                 for (int i = 0; i <= r; i++) {
  24.                    
  25.                     double allJuice = (i * 4.5) + (j * 7.5) + (k * 15.0);
  26.                     boolean isWinner = false;
  27.                     if (allJuice <= maxJuice) {
  28.                         if (juice < allJuice) {
  29.                             isWinner = true;
  30.                         } else if (juice == allJuice) {
  31.                             if (k > cher) {
  32.                                 isWinner = true;
  33.                             } else if (k == cher) {
  34.                                 if (j > str) {
  35.                                     isWinner = true;
  36.                                 } else if (j == str) {
  37.                                     if (i > rasp) {
  38.                                         isWinner = true;
  39.                                     }
  40.                                 }
  41.                             }
  42.                         }
  43.                     }
  44.  
  45.                     if (isWinner) {
  46.                         juice = allJuice;
  47.                         rasp = i;
  48.                         str = j;
  49.                         cher = k;
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.         System.out.printf("%d Raspberries, %d Strawberries, %d Cherries. Juice: %.1f ml.", rasp, str, cher, juice);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement