Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PipesInPool {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int V = Integer.parseInt(scanner.nextLine());
- int P1 = Integer.parseInt(scanner.nextLine());
- int P2 = Integer.parseInt(scanner.nextLine());
- double H = Double.parseDouble(scanner.nextLine());
- double filled = P1*H + P2*H;
- if (V >= 10000){
- System.out.println("Invalid input!");
- } else if (P1 >= 5000) {
- System.out.println("Invalid input!");
- }else if (P2 >= 5000) {
- System.out.println("Invalid input!");
- }else if (H >= 24) {
- System.out.println("Invalid input!");
- }
- else if (filled > V) {
- double overflow = filled - V;
- System.out.printf("For %s hours the pool overflows with %.1f liters.", H, overflow);
- } else {
- double percentall = Math.floor((filled/V)*100);
- double percentP1 = Math.floor(((P1*H)/filled)*100);
- double percentP2 = Math.floor(((P2*H)/filled)*100);
- System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", percentall, percentP1, percentP2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement