Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class TrainingDemo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int raspberries = Integer.valueOf(scanner.nextLine());
- int strawberries = Integer.valueOf(scanner.nextLine());
- int cherries = Integer.valueOf(scanner.nextLine());
- double juiceAllowed = Double.valueOf(scanner.nextLine());
- double juice = 0;
- int ras = 0;
- int str = 0;
- int chr = 0;
- for (int raspberry = 0; raspberry <= raspberries; raspberry++) {
- for (int strawberry = 0; strawberry <= strawberries; strawberry++) {
- for (int cherry = 0; cherry <= cherries; cherry++) {
- double juiceMade = raspberry * 4.5 + strawberry * 7.5 + cherry * 15.0;
- if (juiceMade <= juiceAllowed && juice < juiceMade) {
- juice = juiceMade;
- chr = cherry;
- ras = raspberry;
- str = strawberry;
- }
- }
- }
- }
- DecimalFormat df = new DecimalFormat("0.##");
- System.out.println(String.format("%d Raspberries, %d Strawberries, %d Cherries. Juice: %s ml.", ras, str, chr, df.format(juice)));
- }
- }
Add Comment
Please, Sign In to add comment