Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class FruitDiet {
- 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 kol = Integer.parseInt(scanner.nextLine());
- DecimalFormat df = new DecimalFormat("0.#");
- double sumMax = -1;
- double sum = 0;
- String result = "";
- for ( int i = c; i >= 0; i--) {
- for ( int j = s; j >= 0; j--) {
- for ( int k = r; k >= 0; k--) {
- sum = i * 15 + j * 7.5 + k * 4.5;
- if ( sum <= kol&&sum>sumMax) {
- sumMax=sum;
- result=k+" Raspberries, "+j+" Strawberries, "+i+" Cherries. Juice: "+df.format(sumMax)+" ml.";
- }
- }
- }
- }
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement