Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam26March2016;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Demo {
- 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 vol1=h*p1;
- double vol2=h*p2;
- double totalvol=vol1+vol2;
- double fullpercent=(totalvol/v)*100;
- double percent1=(vol1/totalvol)*100;
- double percent2=(vol2/totalvol)*100;
- if (totalvol<=v){
- System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.", (int)fullpercent, (int)percent1, (int)percent2);
- }
- else {
- DecimalFormat df = new DecimalFormat("0.##");
- System.out.printf("For %s hours the pool overflows with %.1f liters.", df.format(h), totalvol-v);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement