Advertisement
i_jaguar

Untitled

Feb 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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.  
  15.  
  16. double sumMax = -1;
  17. double sum = 0;
  18. String result = "";
  19.  
  20.  
  21. for ( int i = c; i >= 0; i--) {
  22. for ( int j = s; j >= 0; j--) {
  23. for ( int k = r; k >= 0; k--) {
  24.  
  25. sum = i * 15 + j * 7.5 + k * 4.5;
  26.  
  27. if ( sum <= kol&&sum>sumMax) {
  28. sumMax=sum;
  29. result=k+" Raspberries, "+j+" Strawberries, "+i+" Cherries. Juice: "+df.format(sumMax)+" ml.";
  30.  
  31.  
  32.  
  33. }
  34.  
  35. }
  36. }
  37. }
  38. System.out.println(result);
  39.  
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement