java 程序 猴子摘了一些桃子,第一天吃了一半,又多吃了一个,第二天又吃了一半,

Python011

java 程序 猴子摘了一些桃子,第一天吃了一半,又多吃了一个,第二天又吃了一半,,第1张

public static void main(String[] args) {

 int lastday =1

 int days = 10//第十天

 for(int i = 1i<=daysi++){

 lastday=2*(lastday+1)

 }

 //结果是3070个桃子

 System.out.println("一共"+lastday+"个桃子。")

}

public class Myclass {

public static void main(String[] args) {

int day = 9//表示猴子吃桃的天数

int x1 = 0 //表示猴子摘桃的总的个数。

int x2 = 1//表示最后一天所剩的桃子树。

while (day >0) {

x1 = (x2 + 1) * 2

x2 = x1

day = day - 1

}

System.out.println("the total is:" + x1)

}

}