我正在尝试编写一个程序,该程序采用人口的出生率和死亡率并循环年人口,直到它达到 0 或翻倍。
我的问题是它不断循环无数难以辨认的数字,我无法修复它。
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);
}
}