Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Mentorship;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class JuiceDiet {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int raspberries = Integer.parseInt(scanner.nextLine());
- int strawberries = Integer.parseInt(scanner.nextLine());
- int cherries = Integer.parseInt(scanner.nextLine());
- int juice = Integer.parseInt(scanner.nextLine());
- DecimalFormat decimalFormat = new DecimalFormat("0.#");
- String result = "";
- double maxAlcohol = -1;
- for (int i = cherries; i >= 0; i--) {
- for (int j = strawberries; j >= 0; j--) {
- for (int k = raspberries; k >= 0; k--) {
- double currJuice = k * 4.5 + j * 7.5 + i * 15;
- if (currJuice <= juice && maxAlcohol < currJuice) {
- maxAlcohol = currJuice;
- result = k + " Raspberries, " +j + " Strawberries, " + i + " Cherries. Juice: " + decimalFormat.format(maxAlcohol) + " ml.";
- }
- }
- }
- }
- System.out.println(result);
- }
- }
Add Comment
Please, Sign In to add comment