1 dollars a bottle of water, 4 cover for a bottle of water, 150 can drink how much water

Source: Internet
Author: User

First to analyze:

First time: 150
Second time: 150/4 = 37 2
Third time: (37+2)/4 = 9 3
Fourth time: (9 + 3)/4 = 3

3 < 4 so stop

Initial value 150 bottle of water, which is 150 caps

1. Take all the lids to change the water, record the remainder and sum

2. (last remainder + last change of water to drink)/4, record remainder and sum1

......

Infinite loops, until the number of lids <4,

Binding code:

 Public classDemo3 { Public Static voidMain (string[] args) {intn = 150; intsum = 150;  while(N >= 4) {
       int temp = n% 4; N= (int) (N/4);sum+=N; N= n +temp; } System.out.println (sum); }}

1 dollars a bottle of water, 4 cover for a bottle of water, 150 can drink how much water

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.