Suppose there are 50 bottles of drink, 3 empty bottles can be replaced by a bottle of drink, and so on, how many bottles of drink in total?

Source: Internet
Author: User

That's all you can think.

A total of 50 bottles,

Finish three bottles + 1

Finish three bottles + 1

Then 50-3 + 1-3 + 1

And so you know ... The last remaining Coke number is less than 3 exit. Then still test instructions can write.

Package CCCC;
public class Buy {
public static void Main (string[] args) {
int number = 50; Total number of initial beverages
int i=0; Redemption Times
while (true) {
N-= 3; Drink 3 bottles.
n++; Redeem 1 Bottles
i++; Redemption Times +1
if (n<3)
{
System.out.println ("Drink Together" + (50+i) + "bottle");
Break
}
}
}
}

Suppose there are 50 bottles of drink, 3 empty bottles can be replaced by a bottle of drink, and so on, how many bottles of drink in total?

Contact Us

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.