# 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?

Source: Internet
Author: User

` 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?

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.