+ 2
Pls I need a java code to count numbers like this 1, 2, 4, 8, 16, 32, 64
I want the number should count within the target value not to the value I loop it like this for (int I =1; I < 10 ; I *=2 ) the normal out put for this is 1, 2, 8 but I want it to count within the target which is 10 if it count within the target the output will be 1, 2, 4, 8, 32, 64, 128, 256, 512, 1024 it count the numbers 10 times so any who can help should kindle type the code ss comment or message the number on whatsapp pls
5 odpowiedzi
+ 18
//js
for(i=1;i<Math.pow(2,10);i*=2){document.write(i+"<br>")}
+ 3
here it is:
public class Program
{
public static void main(String[] args) {
for(int i = 1; i <= 100; i *= 2){
System.out.print(i);
System.out.print(",");
}
}
}
0
thanks everyone here is the solution to the question
for (int i = 0; i < =100; i+ +)
System.out.println ((int) Math.pow(2, i));
0
it will be more efficient if you use for loop alone with out using any object in it
0
In c ;
Int number=1, declare i also;
For(i=0;I<=10;I++){
// 1. =. 1. *2 then number =2
//. 2. =. 2. *2 then number =4
//. 4. =. 4. *2 then number =8
//. 2. =. 8. *2 then number =16
-----
number=number*2;
Print("%d",number);
}
Output
2481632-----