java - coding errors causing endless loop
- by Daniel Key
Im attempting to write a program that takes a population's birthrate and deathrate and loops the annual population until it either reaches 0 or doubles. My problem it that it continuously loops an endless amount of illegible numbers and i cant fix it. please help.
//*****************************************
//This program displays loop statements
//Written by: Daniel Kellogg
//Last Edited: 9/28/12
//****************************************
import java.util.Scanner;
public class Hwk6 {
public static void main (String[] args) {
int currentYear, currentPopulation;
double birthRate, deathRate;
Scanner stdin = new Scanner(System.in);
System.out.println("\nPopulation Estimator\n");
System.out.println("Enter Year");
currentYear = stdin.nextInt();
System.out.println("Enter Current Population");
currentPopulation = stdin.nextInt();
System.out.println("Enter Birthrate of Population");
birthRate = stdin.nextDouble();
System.out.println("Enter Deathrate of Population");
deathRate = stdin.nextDouble();
int counter = currentPopulation;
System.out.println("Population: ");
while (currentPopulation != -1)
while (counter < currentPopulation * 2) {
System.out.print(counter + " ");
counter = counter + (int)(counter * birthRate - counter * deathRate);
}
System.exit(0);
}
}