Advertisement
i_jaguar

Untitled

Feb 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class FruitDiet {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int r = Integer.parseInt(scanner.nextLine());
  9. int s = Integer.parseInt(scanner.nextLine());
  10. int c = Integer.parseInt(scanner.nextLine());
  11. int kol = Integer.parseInt(scanner.nextLine());
  12. DecimalFormat df = new DecimalFormat("0.#");
  13.  
  14. int i = 0;
  15. int j = 0;
  16. int k = 0;
  17.  
  18. double sumMax = -1;
  19. double sum = 0;
  20. String result = "";
  21.  
  22.  
  23. for ( i = c; i >= 0; i--) {
  24. for ( j = s; j >= 0; j--) {
  25. for ( k = r; k >= 0; k--) {
  26.  
  27. sum = i * 15 + j * 7.5 + k * 4.5;
  28.  
  29. if ( sum <= kol&&sum>sumMax) {
  30. sumMax=sum;
  31. result=k+" Raspberries, "+j+" Strawberries, "+i+" Cherries. Juice: "+df.format(sumMax)+" ml.";
  32.  
  33.  
  34.  
  35. }
  36.  
  37. }
  38. }
  39. }
  40. System.out.println(result);
  41.  
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement