JAVA 编程-----------------17、猴子吃桃问题

 1 package FushiExam;
 2 
 3 public class Text_17 {
 4 
 5     public static void main(String[] args) {
 6         /*猴子吃桃问题:
 7          * 猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,有多吃了一个
 8          * 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。
 9          * 以后每天早上都吃前一天剩下的一半零一个。
10          * 到第10天早上再想吃的时候,见只剩下一个了,求第一天摘了多少个
11          * 
12          */
13         int total=1;
14         for(int i=0;i<9;i++) {
15             total=(total+1)*2;
16         }
17         System.out.println(total);
18 
19     }
20 
21 }

猜你喜欢

转载自www.cnblogs.com/fmust/p/12489008.html