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