Results 1 to 4 of 4
Thread: Java problem help!
 10222009, 12:46 PM #1Member
 Join Date
 Oct 2009
 Posts
 1
 Rep Power
 0
Java problem help!
Ok so I am studying Java for the first time and am really stuck on the following program.
The population of a town is now at 15000 and it is expanding at 5% per year . Write a program to determine how many years it will take for the population to exceed 85000.
I understand mathematically how you get the answer but not in java.
Can anyone help me, please
Below is my lousy attempt :)
import java.util.*;
population
{
//The population of a town is now at 15000 and it is expanding at 5% per year . Write a program to determine how many years it will take for the population to exceed 85000.
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
// variables
double population, year1, year2, yearn;
final DOUBLE ENDPOP = 85000;
// initialise loop control variable
while (population < ENDPOP)
{
// year 1 population increase
System.out.println("enter current population");
population = sc.nextDouble():
year1 = (population * 1.05);
year2 = (year1 * 1.05);
yearn = (year(n1) * 1.05);
} // end while
System.out.println("Number of years for population to exceed 85000 is " + ?);
}// end main
}// end class
 10222009, 01:14 PM #2Senior Member
 Join Date
 Aug 2009
 Posts
 2,388
 Rep Power
 13
How would you get the answer mathematically? Write down those steps.
Then convert the steps to a Java program.
 10262009, 12:26 PM #3Member
 Join Date
 Aug 2009
 Posts
 1
 Rep Power
 0
class Population
{
public static void main(String args[])
{
double intialpopulation=15000D;
double finalpopulation=85000D;
double percentage=5;
double yearlyIncreaseinpoulation=(percentage/100)*intialpopulation;
System.out.println("yearlyIncreaseinpoulation"+yea rlyIncreaseinpoulation);
double noofyears=(finalpopulationintialpopulation)/yearlyIncreaseinpoulation;
System.out.println(noofyears);
}
}
 10262009, 12:52 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
That most certainly isn't true: if you start with a population P(0) and the growth is i percent per year, then after n years the population P(n) is: (1+i/100)^n*P(0); if you have P(0) == 15000 and P(n) == 85000 then a bit of 101 math tells you: 85000 ==1.05^n*15000 > 85000/15000= 1.05^n > n == 35.5... little babies grow up and start making little babies too you know.
kind regards,
Jos
Similar Threads

Java Problem. Need Help!
By bob101 in forum New To JavaReplies: 6Last Post: 03192009, 04:34 AM 
JAVA and XML Problem
By jackchang in forum XMLReplies: 4Last Post: 02222009, 08:28 PM 
Java problem
By grend in forum New To JavaReplies: 5Last Post: 08182008, 11:44 PM 
Problem in java
By saytri in forum New To JavaReplies: 6Last Post: 01092008, 04:13 PM 
java SE 6 problem
By techlance in forum Java AppletsReplies: 1Last Post: 06282007, 10:10 AM
Bookmarks