Packagecom.study.day07;ImportJava.util.Scanner;/*** 28 people buy cola drink, 3 Coke bottle cap can change a bottle of coke, * so how many bottles of Coke to buy, enough for 28 people to drink? If it is 50 people, how many bottles of Coke do you need to buy? (Need to write analysis ideas) * Answer: 28 people need to buy 19 bottles, 50 people need to buy 34 bottles. * @authorDenny * Ideas: 1. First buy a bottle of * 2. The number of Caps/3 can be used to change multiple bottles * 3. Cycle Conditions 28 Bottles*/ Public classTest { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); //How many people to drink?System.out.println ("Please enter how many bottles you want to buy"); intCount=Input.nextint (); GetCount (count); } Public Static voidGetCount (intcount) { intTemp=0;//Number of Caps intbuyping=0;//Current number of bottles intSendping=0; while(sendping+buyping!=count) {buyping++;//Buy one more bottletemp++;//number of Caps +1 if(temp/3==1) {sendping++;//bottle of Gift +1Temp=temp-2;//The bottle cap is recalculated for a bottle and more a cap temp-3+1, so it is 12 can also be directly temp=1 assignment}} System.out.println ("Bought:" +buyping+ "Sent:" +sendping); } }
28 people buy cola drink, 3 Coke bottle cap can change a bottle of Coke, then how many bottles of Coke to buy, enough for 28 people to drink? If it is 50 people, how many bottles of Coke do you need to buy?