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. ## Static Method Help

I'm trying to use a static method to find out how many years it takes to double an arbitrary amount of money so I used a dummy amount of money. The problem is, the code compiles but the code does not run properly. What am I doing wrong?
```class YearsToDouble
{
public static void main ( String [] args ) throws Exception
{
System.out.println("rate(percent)   years to double");
for ( int percent : new int[] {1,2,3,4,6,9,12,24} ) line(percent);
}
public static void line ( int percent )
{
System.out.printf("%7d%17d\n",percent,yearsToDouble(percent));
}
public static int yearsToDouble ( int percent )
{
double balance = 1.00;
int years = 0;
while ( balance < 2.00)
{
balance += ((percent/100)*balance);
years++;
}
return years;
}
}```

2. ## Re: Static Method Help

```while ( balance < 2.00)
{
balance += ((percent/100)*balance);
years++;
}```

That's an infinite loop.
1 / 100, 24 / 100, calculated as Integers equate to 0.

So you're always saying, 0 * balance, which of course equals zero, hence infinite loop

3. ## The Following User Says Thank You to newbie For This Useful Post:

mysticCHEEZE (October 9th, 2011)

4. ## Re: Static Method Help

Now I get it Thanks!