- import java.util.*;
- class Peachdemo{
- private int day; //已经吃的天数
- private long peach; // 剩余的桃子数
- void run(int con_day ,long peachs)
- {
- peach = peachs;
- for (day=con_day;day>0;day--)
- {
- peach=(peach+1)*2;
-
- }
- System.out.println("第一天共摘了"+peach+"个桃子");
- if(peach>=3000){
- System.out.println("这他妈是孙悟空吧!");
- }
- }
- }
- public class Monkeyeatpeach {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- Peachdemo p=new Peachdemo();
- System.out.println("请输入你的天数:");
- int day = in.nextInt();
- System.out.println("请输入你最后一天剩余的桃子:");
- int peach = in.nextInt();
- p.run(day,peach);
-
- }
- }
复制代码 猴子吃桃问题
|
|