marking2112

JuiceDiet

Jul 20th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class TrainingDemo {
  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.         double maxJuice = Double.parseDouble(scanner.nextLine());
  12.  
  13.         double juice = 0;
  14.         int rasp = 0;
  15.         int str = 0;
  16.         int cher = 0;
  17.  
  18.         for (int i = 0; i <= r; i++) {
  19.             for (int j = 0; j <= s; j++) {
  20.                 for (int k = 0; k <= c; k++) {
  21.                     double allJuice = (i * 4.5) + (j * 7.5) + (k * 15.0);
  22.                     if (allJuice <= maxJuice && juice < allJuice) {
  23.                         juice = allJuice;
  24.                         rasp = i;
  25.                         str = j;
  26.                         cher = k;
  27.                     }
  28.                 }
  29.             }
  30.  
  31.         }
  32.         DecimalFormat df = new DecimalFormat("0.##");
  33.         System.out.printf("%d Raspberries, %d Strawberries, %d Cherries. Juice: %s ml.", rasp, str, cher, df.format(juice));
  34.     }
  35. }
Add Comment
Please, Sign In to add comment