循环不会打印

时间:2017-10-13 15:25:05

标签: java

我正在编写一个计划,计算3,4,5,6和7名员工10-40小时后的工资额。我已经编写了我的代码,用于循环,并认为我做得正确。但是循环不会打印。运行程序后唯一出现的是在循环之前写入的system.out.print。这是我的计划。

public class Prog166d {
    // declares hourly wage as a constant 
    public static final int hourlyRate = 8;

    public static void main(String[] args) {
        System.out.println(" Wages for 3 employees\n\n");

        //loop that increments employees.
        for (int employees = 3; employees >= 7; employees++) {
            System.out.println(" Wages for " + employees + " employees\n\n");

            //loop to calculate wage 
            for (int hours = 10; hours <= 40; hours += 10) {
                int wages = hourlyRate * hours;

                //output
                System.out.println("For" + hours + " hours worked, the wages are " + wages + "dollars");
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

你的问题是for (int employees= 3; employees>=7; employees++) 这样它就永远不会进入循环因为3<7

employees>=7需要替换为employees<=7