猴子摘桃问题

xiaoxiao2021-02-28  35

package task_3_7; public class Task04 { public static void main(String[] args) { // 猴子摘桃 // 一天吃一半多1个,到第十天剩下1个,求第一天有几个。 // 使用while语句 // 10 9 8 7 ... // 1 4 10 22 ... int i = 10; //第几天 int peachCount = 1; //桃子个数 while(i >= 1) { peachCount = (peachCount+1)*2; i--; } System.out.println(peachCount); } }
转载请注明原文地址: https://www.6miu.com/read-2619930.html

最新回复(0)