Home  >  Article  >  Java  >  java - monkey eating peach problem

java - monkey eating peach problem

王林
王林forward
2019-11-26 13:59:003297browse

java - monkey eating peach problem

Title description:

Wukong picked a few peaches on the first day, and ate half of them immediately. It was not enough, so he ate one more, and there were still some leftovers the next day. He ate more than half of the peaches he laid, and he ate more than half of the remaining peaches from the previous day every day. When he was ready to eat on the nth day, only one peach was left. If you are smart, please help Wukong calculate how many peaches there were when he started eating on the first day?

Recommended related video tutorials: java online tutorial

Input:

Enter a number n (1<=n<=30).

Output:

Output the number of peaches on the first day.

Sample input:

3

Sample output:

10

Program code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		int a=1;
		for(int i=1;i

If you want to know more about related issues, you can visit: javaQuick Start. There are many Java-related articles here. Everyone is welcome to learn together!

The above is the detailed content of java - monkey eating peach problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete