Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class JuiceDiet06 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int r = Integer.parseInt(scanner.nextLine());
- int s = Integer.parseInt(scanner.nextLine());
- int c = Integer.parseInt(scanner.nextLine());
- int juiceMax = Integer.parseInt(scanner.nextLine());
- double max = 0;
- int maxRasp = 0;
- int maxStraw = 0;
- int maxCherries = 0;
- for (int i = 0; i <= r; i++) {
- for (int j = 0; j <= s; j++) {
- for (int k = 0; k <= c; k++) {
- double cherries = 15 * k;
- double strawberries = 7.5 * j;
- double raspberries = 4.5 * i;
- double juiceCurrent = cherries + strawberries + raspberries;
- if (juiceCurrent <= juiceMax)
- {
- if (juiceCurrent > max)
- {
- maxRasp = i;
- maxStraw = j;
- maxCherries = k;
- max = juiceCurrent;
- }
- }
- if (juiceCurrent == juiceMax - 1 || juiceCurrent == juiceMax) {
- if (cherries > strawberries && cherries > raspberries || strawberries > raspberries){
- System.out.printf("%s Raspberries, %s Strawberries, %s Cherries. Juice: %.0f ml.", i, j, k, juiceCurrent);
- return;
- }
- else{
- System.out.printf("%s Raspberries, %s Strawberries, %s Cherries. Juice: %.0f ml.", i, j, k, juiceCurrent);
- return;
- }
- }
- }
- }
- }
- System.out.printf("%s Raspberries, %s Strawberries, %s Cherries. Juice: %s ml.", maxRasp, maxStraw, maxCherries, max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement