Advertisement
Spocoman

Juice Diet

Sep 7th, 2024
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int r = Integer.parseInt(scanner.nextLine()),
  7.                 s = Integer.parseInt(scanner.nextLine()),
  8.                 c = Integer.parseInt(scanner.nextLine()),
  9.                 maxJuice = Integer.parseInt(scanner.nextLine()),
  10.                 raspberries = 0, strawberries = 0, cherries = 0;
  11.         double juice = 0;
  12.  
  13.         for (int j = 0; j <= r; j++) {
  14.             for (int k = 0; k <= s; k++) {
  15.                 for (int l = 0; l <= c; l++) {
  16.                     double currentJuice = 4.5 * j + 7.5 * k + 15 * l;
  17.                     if (juice < currentJuice && currentJuice <= maxJuice) {
  18.                         juice = currentJuice;
  19.                         raspberries = j;
  20.                         strawberries = k;
  21.                         cherries = l;
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.  
  27.         System.out.printf("%d Raspberries, %d Strawberries, %d Cherries. Juice: %d ml.", raspberries, strawberries, cherries, (int) juice);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement