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 r = Integer.parseInt(scanner.nextLine());
- int s = Integer.parseInt(scanner.nextLine());
- int c = Integer.parseInt(scanner.nextLine());
- double maxJuice = Double.parseDouble(scanner.nextLine());
- double juice = 0;
- int rasp = 0;
- int str = 0;
- int cher = 0;
- for (int i = 0; i <= r; i++) {
- for (int j = 0; j <= s; j++) {
- for (int k = 0; k <= c; k++) {
- double allJuice = (i * 4.5) + (j * 7.5) + (k * 15.0);
- if (allJuice <= maxJuice && juice < allJuice) {
- juice = allJuice;
- rasp = i;
- str = j;
- cher = k;
- }
- }
- }
- }
- DecimalFormat df = new DecimalFormat("0.##");
- System.out.printf("%d Raspberries, %d Strawberries, %d Cherries. Juice: %s ml.", rasp, str, cher, df.format(juice));
- }
- }
Add Comment
Please, Sign In to add comment