4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by moutanna
1

OK friend, i am telling you the answer of this question. but it is so simple. Do little work before posting.

public static void main(String[] args) {
int initial = 1;
for(int i=0 ; i <= 10; i++){
System.out.println(initial);
initial = initial*2;
}
}

Edited by happygeek: fixed formatting

0

Hi;
May be the idea here is to understand how the binary numbers works;the numbers you print are all the power of 2.
you can do some thing lik:

public static void main(String[] args) {
        for (int i = 0; i <= 9; i++) {
            System.out.println(Math.pow(2, i));
        }
    }

if you did not want the digits after the point you can cast the result to int like this

public static void main(String[] args) {
        for (int i = 0; i <= 9; i++) {

            System.out.println((int)Math.pow(2, i));
        }
    }

or you can use the NumberFormat.

Hope it halps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.