我想打印输出:1 3 5 7 9 11 13 15 17 19 21 1 3 5 7 9 11 但我得到这个输出:1 34 67 910 1213 1516 1819 211 34 67 910 1213 1516 1819 21
有人可以解释一下我在逻辑上犯的错误吗?
public class BadNews {
public static final int MAX_ODD = 21;
public static void writeOdds() {
// print each odd number
for ( int count = 1; count <= (MAX_ODD - 2); count++) {
System.out.print(count + " ");
count = count + 2;
// print the last odd number
System.out.print(count);
}
}
public static void main(String[] args) {
// write all odds up to 21
writeOdds();
// now, write all odds up to 11
writeOdds();
}
}