# Need Help on Questions

Page 1 of 1

## 5 Replies - 499 Views - Last Post: 06 February 2017 - 09:21 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=401158&amp;s=9241cc7ac03345bc241964482bb714a7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Beginner4ever

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 06-February 17

# Need Help on Questions

Posted 06 February 2017 - 06:01 PM

I can't for the life of me figure this out, and I'm close to having to drop out of the class.

1. Write a method called printPowersOf2 that accepts the maximum number as an argument and prints each power of 2 from 2^0 up to the maximum number. For example, consider the following calls:

printPowersOf2(3);
printPowersOf2(10);

Output should look like this:

1 2 4 8
1 2 4 8 16 32 64 128 256 512 1024

.. I couldn't succesfully write a method without an error.. my code looked like this but won't run:
```public static void double (int max)

Math.pow(2,i);

for(int i=0;i<=10;i++);
System.out.println(Math.pow(2,i));

```

I really need help on this and the teacher can't seem to explain it to me.

Is This A Good Question/Topic? 0

## Replies To: Need Help on Questions

### #2 modi123_1

• Suitor #2

Reputation: 14413
• Posts: 57,793
• Joined: 12-June 08

## Re: Need Help on Questions

Posted 06 February 2017 - 06:31 PM

Can't run how? Errors, where?

For loop conditions do not need semi colons after them. I am thinking the error messages tell you as much.

```5 for(int i=0;i<=10;i++);
```

### #3 Beginner4ever

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 06-February 17

## Re: Need Help on Questions

Posted 06 February 2017 - 06:53 PM

Thank you I was able to figure out at least the symtax error:

```for(int i=0; i<=3; i++)
System.out.println(Math.pow(2,i));

for(int i=0; i<=10; i++)
System.out.println(Math.pow(2,i));
}

```

But how would I create a method named powersOf2? The teacher never explained the criteria of methods, classes, objects.

### #4 Beginner4ever

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 06-February 17

## Re: Need Help on Questions

Posted 06 February 2017 - 07:00 PM

I know you really didn't do much but thank you. I tend to go catastrophic mode when I can't figure something out and give up.

I figured it out:

```public class JavaApplication3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
printPowersOf2();

}

static void printPowersOf2() {
for(int i=0; i<=3; i++)
System.out.println(Math.pow(2,i));

for(int i=0; i<=10; i++)
System.out.println(Math.pow(2,i));
}

```

It may not seem like much but to me this is a big victory. thanks

### #5 Beginner4ever

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 06-February 17

## Re: Need Help on Questions

Posted 06 February 2017 - 07:01 PM

I know you really didn't do much but thank you. I tend to go catastrophic mode when I can't figure something out and give up.

I figured it out:

```public class JavaApplication3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
printPowersOf2();

}

static void printPowersOf2() {
for(int i=0; i<=3; i++)
System.out.println(Math.pow(2,i));

for(int i=0; i<=10; i++)
System.out.println(Math.pow(2,i));
}

```

It may not seem like much but to me this is a big victory. thanks

I know you really didn't do much but thank you. I tend to go catastrophic mode when I can't figure something out and give up.

I figured it out:

```public class JavaApplication3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
printPowersOf2();

}

static void printPowersOf2() {
for(int i=0; i<=3; i++)
System.out.println(Math.pow(2,i));

for(int i=0; i<=10; i++)
System.out.println(Math.pow(2,i));
}

```

It may not seem like much but to me this is a big victory. thanks

### #6 modi123_1

• Suitor #2

Reputation: 14413
• Posts: 57,793
• Joined: 12-June 08

## Re: Need Help on Questions

Posted 06 February 2017 - 09:21 PM

Quote

I know you really didn't do much but thank you.

Snap! Rhythm is a dancer..