Computer Science, asked by amrapali96, 7 months ago

Language program.There is a Bucket of water capacity of x litres,

which is supposed to fill with a mug of y millilitres water capacity.

Say for example x=100 and y=10 less than 100%>. Bucket filling is to be stopped once more than 80% of bucket capacity is filled. The amount of water taken at a time in to stop once bucket is full that is poured into bucket. Note that greater that Mug's Capacity.

then, bucket will get full of minimum of 8 mugs (> 80% and

mug is not fixed as it can be any value less than or equal to y Notify

more than 80% of capacity of bucket and count number of mugs

Bucket capacity will always be
as // Enter Mug capacity in litres as 20 20 20 20 .output values bucket full!no.of mugs:4 .write a problem on c,c++,java

more than 80% of capacity of

greater that Mug's Capacity. Example 1: INPUT VALUES 100 this 20 // Enter Bucket capacity in litres

this 2 // enter amount of water in MUG one after other as below 20

Answers

Answered by KunalNamdev
0

Answer:

import java.util.Scanner;

public class Bucket {

 

public static void check(int a,int b){

 int count=0,fill=0;double cal=0;int flag=0;

 cal = a*0.8;

 if(b>a){

  flag=1;

 }

 else{

  System.out.println("Enter your amount of water in mugs");

  while(fill<cal){

   Scanner sc = new Scanner(System.in);

   int mugs = sc.nextInt();

   if(mugs>b || mugs<0){

    flag=1;

    break;

   }

   else{

    fill+=mugs;

    count+=1;

   }

  }

   

 }

 if(flag==0){

  System.out.println("Number of mugs to fill a bucket :"+count);

 }

 else{

  System.out.println("Invalid input");

 }

}

public static void main(String[] args) {

 Scanner sc = new Scanner(System.in);

 System.out.println("Enter a Bucket Size in Lit and Size of Mug");

 int bsx =sc.nextInt();

 int msx = sc.nextInt();

 

 check(bsx,msx);

}

}

Explanation:

Similar questions