新Java程序员,这个程序有什么问题?

Col*_*ury 0 java eclipse

它达到了必须打印线的程度System.out.printf("%4s%22s%24s\n","Year"...),然后在没有打印的情况下停止.

public class WorldPopulationGrowth {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner input = new Scanner( System.in);
        long BasePopulation; //The base, or current population
        double GrowthRate; //The rate of increase
        double GrowthResult; // The pop after growth rate increase

        //Time to obtain the numbers needed for Calculation
        //Specifically, the growth rate and the base population
        System.out.println("Welcome to the world population calculator");
        System.out.print("Enter the current world population:");
        BasePopulation = input.nextLong();
        System.out.println("Enter the current growth rate: (e.g, 1.14% would be .0114): ");
        GrowthRate = input.nextDouble();
        int Year = 1; //I need this for the next part
        System.out.printf("%4s%22s%24s\n", "Year", "Estimated Population", "Change from prior Year");
        while (Year <= 75); {// Start of the while
            GrowthResult = BasePopulation * (1 + GrowthRate);
            System.out.printf("%4d%22d%24d\n", Year, (long) GrowthResult, (long) GrowthResult - BasePopulation);
            BasePopulation = (long) GrowthResult;
        }//End of the while
    }//End of public static
}//End of class
Run Code Online (Sandbox Code Playgroud)

ysh*_*vit 7

while循环后你有一个分号.分号是一个空语句,就是在循环中执行的内容.之后,您有一个匿名块(这是您希望在循环中执行的).它相当于:

while (Year <= 75) {
    // empty
}
{
    // anonymous block
    GrowthResult = BasePopulation * (1 + GrowthRate);
    ...
Run Code Online (Sandbox Code Playgroud)

解决方法是删除分号.