Java 打印while循环

Java 打印while循环,java,Java,} 我在打印循环时遇到问题。每次我运行程序时,这个段只打印出一个数字,而不打印出其余的数字 per@ajb您不想在循环中执行类似的操作吗?这将打印您每年的加薪,并将其添加到下一次迭代的薪资中 根据你的新评论 每次它们是一个输出,我都希望它显示年份和时间 他们的薪水 可能是这样的 while (year > years) { //predict = salary * (pi/100); commented this because it is not necessary anymo

}


我在打印循环时遇到问题。每次我运行程序时,这个段只打印出一个数字,而不打印出其余的数字

per@ajb您不想在循环中执行类似的操作吗?这将打印您每年的加薪,并将其添加到下一次迭代的薪资中

根据你的新评论

每次它们是一个输出,我都希望它显示年份和时间 他们的薪水

可能是这样的

while (year > years) {

    //predict = salary * (pi/100); commented this because it is not necessary anymore.
    salary += salary * (pi/100);

    System.out.println(years + ". " + salary); // replaced predict with salary, to show their salary and not just their predicted raise.
    years++;

    // This block of code will never be hit, therefore it is not needed.   
    //if (years == year){
    //    break;
    //}
}   

如果我说X+Y!=如果你不知道X和Y是什么,你怎么能帮我?考虑添加一些上下文。在整个主要方法中,我补充说,不管你输入哪一年,这都会发生。我想我知道你在问什么,但是你没有把它说得很好。所以问题是它打印出了几行输出,但每次预测的工资都是一样的?这在很多公司听起来都是正确的答案:你真的应该这么说,包括输入和输出以及你认为输出错误的原因。是的,很抱歉,这是我第一次使用这个。实际上你甚至不需要最后一个if语句:这个语句中的条件对他的意思非常不清楚。。。第一个有条件的州不读去年,而最后一个有条件的州意味着他应该打印去年。所以我把它放在那里,因为我不确定。当使用双精度时,如何只输出小数点后两位的工资?
while (year > years) {

    //predict = salary * (pi/100); commented this because it is not necessary anymore.
    salary += salary * (pi/100);

    System.out.println(years + ". " + salary); // replaced predict with salary, to show their salary and not just their predicted raise.
    years++;

    // This block of code will never be hit, therefore it is not needed.   
    //if (years == year){
    //    break;
    //}
}   
while (year > years) {
    salary += salary * (pi/100);
    System.out.println(years + ". " + salary);
    years++;
}