public class poundtokilogram {
public static void main(String[] args) {
    System.out.println("Kilograms     Pounds   |   Pounds     Kilograms");
    System.out.println("-----------------------------------------------");

    int kilos = 1;
    int pounds = 20;

    for ( kilos = 1; kilos > 200; kilos++ ) {
        for ( pounds = 20; pounds > 515; pounds++) {
            double kiloc = pounds * .453;
            double poundc = kilos * 2.2;
            System.out.print(kilos + "    " + poundc + " | " + pounds + "     " + kiloc + "\n");
        }
    }
}


}

这是代码,从本质上讲,我试图打印出一张转换表,其中一侧为千克到磅,另一侧为磅到千克(这只是我正在学习的书中的一种练习),出于某种原因,运行它只会打印出前两行。顺便说一句,第一次发布到StackOverflow,关于如何变得更加清晰的建议将不胜感激。

最佳答案

您正在检查kilos大于200并且磅大于515

改变这个

for ( kilos = 1; kilos > 200; kilos++ ) {
for ( pounds = 20; pounds > 515; pounds++) {




for ( kilos = 1; kilos < 200; kilos++ )
for ( pounds = 20; pounds < 515; pounds++) {

09-11 13:06