desislava_topuzakova

06.JuiceDiet

Mar 11th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package TestJan;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class JuiceDiet {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int raspberries = Integer.parseInt(scanner.nextLine());
  10. int strawberries = Integer.parseInt(scanner.nextLine());
  11. int cherries = Integer.parseInt(scanner.nextLine());
  12. int juice = Integer.parseInt(scanner.nextLine());
  13. DecimalFormat decimalFormat = new DecimalFormat("0.#");
  14. String result = "";
  15. double maxAlcohol = -1;
  16.  
  17. for (int i = cherries; i >= 0; i--) {
  18. for (int j = strawberries; j >= 0; j--) {
  19. for (int k = raspberries; k >= 0; k--) {
  20. double currJuice = k * 4.5 + j * 7.5 + i * 15;
  21. if (currJuice <= juice && maxAlcohol < currJuice) {
  22. maxAlcohol = currJuice;
  23. result = k + " Raspberries, " +j + " Strawberries, " + i + " Cherries. Juice: " + decimalFormat.format(maxAlcohol) + " ml.";
  24. }
  25. }
  26. }
  27. }
  28.  
  29. System.out.println(result);
  30. }
  31. }
Add Comment
Please, Sign In to add comment