Advertisement
Ivakis

Тръби в басейн

Sep 28th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package exam18december;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class trubi {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int v = Integer.parseInt(scanner.nextLine());
  10. int p1 = Integer.parseInt(scanner.nextLine());
  11. int p2 = Integer.parseInt(scanner.nextLine());
  12. double h = Double.parseDouble(scanner.nextLine());
  13.  
  14. double p1Result = p1 * h;
  15. double p2Result = p2 * h;
  16.  
  17. double totalResult = p1Result + p2Result;
  18.  
  19. if (totalResult <= v) {
  20. double all = Math.floor(totalResult / v * 100);
  21. double p1Percent = Math.floor(p1Result / totalResult * 100);
  22. double p2Percent = Math.floor(p2Result / totalResult * 100);
  23.  
  24. System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", all, p1Percent, p2Percent);
  25. } else {
  26. double all = totalResult - v;
  27. if (h % 1 == 0) {
  28. System.out.printf("For %.0f hours the pool overflows with %.1f liters.", h, all);
  29. } else {
  30. System.out.printf("For %.1f hours the pool overflows with %.1f liters.", h, all);
  31. }
  32.  
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement