如何在java

时间:2017-10-07 20:49:49

标签: java for-loop

序列是2 1 4 3 6 5 8 7 10 9 12 11 ....... 仅在Java中使用for循环 非常感谢任何答案

如果其他方面是我们必须打印n n-1

1 个答案:

答案 0 :(得分:0)

public static void main(String[] args) {
    int n = 8; //set anything here
    for (int even = 2, odd = 1;even<=n;even+=2,odd+=2){
        System.out.print(even+" "+odd+" ");
    }
}