Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## season tree

Problem Statement:
In a forest near Bandipur in INDIA, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons.The season always starts with winter.

--- Update ---

import java.util.Scanner;

public class Tree {

public static void main(String args[]) {
int length;
int season;
int su, wi;
int sum = 0;
int n = 0;
int TotalLength=0;

System.out.println("enter the number of seasons");
Scanner in = new Scanner(System.in);
season = in.nextInt();
System.out.println("enter the length of tree");
length = in.nextInt();
System.out.println("enter the total number of trees in forest");
n = in.nextInt();

for (int i = 0; i < (season); i++) {
if ((i % 2) == 0) {
length = length * 2;
}

if ((i % 2) != 0) {
length = length + 1;
}
}
TotalLength = length*n;
System.out.println("the total trees lenght is: " + TotalLength);

}
}