猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
用Java程序计算出结果
package ch01入门.day_02; public class Test_monkey { public static void main(String[] args) { int x =1; int y = 0; int t = 0; for (int i = 9; i>0 ; i--) { y = x*2+2; x = y; t = y; } System.out.println(t); } }