Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package juicediet;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class JuiceDiet {
- 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 maxJuice = Integer.parseInt(scanner.nextLine());
- double juice = 0;
- int rasp = 0;
- int str = 0;
- int cher = 0;
- for (int k = 0; k <= c; k++) {
- for (int j = 0; j <= s; j++) {
- for (int i = 0; i <= r; i++) {
- double allJuice = (i * 4.5) + (j * 7.5) + (k * 15.0);
- boolean isWinner = false;
- if (allJuice <= maxJuice) {
- if (juice < allJuice) {
- isWinner = true;
- } else if (juice == allJuice) {
- if (k > cher) {
- isWinner = true;
- } else if (k == cher) {
- if (j > str) {
- isWinner = true;
- } else if (j == str) {
- if (i > rasp) {
- isWinner = true;
- }
- }
- }
- }
- }
- if (isWinner) {
- juice = allJuice;
- rasp = i;
- str = j;
- cher = k;
- }
- }
- }
- }
- System.out.printf("%d Raspberries, %d Strawberries, %d Cherries. Juice: %.1f ml.", rasp, str, cher, juice);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement