andkamen

тръби

Mar 16th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package com.utilities;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class VegFruit {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int V = Integer.parseInt(scanner.nextLine());
  11.         int P1 = Integer.parseInt(scanner.nextLine());
  12.         int P2 = Integer.parseInt(scanner.nextLine());
  13.         double N = Double.parseDouble(scanner.nextLine());
  14.  
  15.         double sum = (N * P1) + (N * P2);
  16.  
  17.         if (sum <= V) {
  18.             int x = (int) ((sum / V) * 100);
  19.             int y = (int) (((N * P1) / sum) * 100);
  20.             int z = (int) (((N * P2) / sum )* 100);
  21.             System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.", x, y, z);
  22.         } else if (sum > V) {
  23.             double q =  sum - V;
  24.             System.out.printf("For %s hours the pool overflows with %s liters.",
  25.                     new DecimalFormat("#.##").format(N),  new DecimalFormat("#.##").format(q));
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment