开发者

arrange following number

开发者 https://www.devze.com 2023-01-31 13:48 出处:网络
Output 2 4 5 8 16 17 32 64 127 128 129 with Java+for i try to.. int num=2; for(int n=1;n<=11;n++){ if(n%3==0 || n%10==0){

Output 2 4 5 8 16 17 32 64 127 128 129

with Java+for

i try to..

    int num=2;
    for(int n=1;n<=11;n++){

        if(n%3==0 || n%10==0){
            num+=1;

            System.out.println(num);

 开发者_开发百科       }else{

        num=n*2;

        System.out.println(num);

        }
    }

}

but fail.. can anyone advice me plz


int num = 1;
for (int n = 1; n < 12; n++) {
    if (n > 8) {
        System.out.println(n + 118);
    } else if (n % 3 == 0) {
        System.out.println(num + 1);
    } else {
        num *= 2;
        System.out.println(num);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消