# Thread: Using exponential functions in Java.

1. ## Using exponential functions in Java.

The program itself is simple enough. However, I'm clueless as to how I should implement this math problem in this for loop... I do have the program itself done, of course.

Code:
```public class PopulationGrowth
{

public static void main(String[] args)
{
double pop = 231;
int popCounter = 1980;

for (popCounter = 1980; popCounter <= 2013; ++popCounter)
{
pop = pop * ???????;
}
System.out.printf("The population in 2013 is approximately: %f million.", pop);

}

}```
Question marks should be obvious.

Basically, I'm supposed to predict the population growth from 1980 to 2013, with a 1.03% increase from a 231 million population.

I know it's 231 * (1.103)33. My question is... how do I write that in code? Since it's a for loop, the exponential value would be the counter, but that's all I got.

In case you're wondering, this assignment is to practice the use of for loops, so doing it like this is pretty much the entire point of the assignment.

EDIT: IT'S 1.0103 AND SHOULD NOT BE INCLUDING 2013. Okay oops.

2. ## Re: Using exponential functions in Java.

pop *= 1.03;

?

I fail to understand.

3. ## Re: Using exponential functions in Java.

Why does this need a loop?

Your loop parameters should not be inclusive of 2013 as that's 34 years, and it should be 1.0103 not 1.03 Danny, geez.

4. ## Re: Using exponential functions in Java.

I did that at first, but I got a different answer from what I calculated...

I'm probably extremely stupid. ;_;

Ask my teacher, she assigned this.

5. ## Re: Using exponential functions in Java.

Oh it's a 1.03% increase.
Pffft..

> Why does this need a loop?

> In case you're wondering, this assignment is to practice the use of for loops, so doing it like this is pretty much the entire point of the assignment.

You didn't read either. So shhh

6. ## Re: Using exponential functions in Java.

NOTE: I'm a bit of a newbie, but I think I can help.

First of, the pineapple is up with your for loop? Wouldn't that reset the year (popCounter) back to 1980 each time it loops?

As for your real question, you have to multiply the amount the population increases by 1.103 each time it loops, assuming I'm understanding the problem right.

double pop = 231;
int popCounter = 1980;
double percentIncrease = 1.103;

for (popCounter = 1980; popCounter <= 2013; ++popCounter)
{

percentIncrease = percentIncrease * percentIncrease;
}

pop = pop * percentIncrease;

System.out.printf("The population in 2013 is approximately: %f million.", pop);

7. ## Re: Using exponential functions in Java.

HAHA OOPS APPARENTLY I CAN'T MATH.

Thanks, it works now. :|

8. ## Re: Using exponential functions in Java.

Oh, I missed that part.

Too bad she never told us how to do that. :(

10. ## Re: Using exponential functions in Java.

Ooh, did not know that was a thing. I was under the impression there was only %d/%f/%s. I'll definitely read up more on that.

Thanks!

11. ## Re: Using exponential functions in Java.

I've seen you study some pretty in-depth CS classes, how come you're still on a pretty basic programming level?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•