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);
}
}
精彩评论