1. Member
Join Date
Oct 2010
Posts
56
Rep Power
0

## For Loops

Hi guys. Hope you are well. I'm particularly stuck on understanding for loops properly. I have this program which computes numbers to whatever power you want it to. There are two command line arguments, the first being the number and the second being the power:

Java Code:
```public class Power
{
public static void main(String [] args)
{
int number = Integer.parseInt(args[0]);
int power = Integer.parseInt(args[1]);

for (int i = 0; i*i < power; i++)

}
}```
Can anyone help on correcting this problem and possibly explaining how the for loop works, because i'm so confused :S

Kind regards

Shyam

2. ## Re: For Loops

help on correcting this problem
Can you explain what the problem is?
Post any output and explain what is wrong with it and show what it should be.

Have you worked out the problem on a piece of paper doing the math one operation on each line to see what the pattern is that you want in the loop?
Last edited by Norm; 09-27-2011 at 05:19 PM.

3. ## Re: For Loops

Crossposted: For Loops

4. Member
Join Date
Oct 2010
Posts
56
Rep Power
0

## Re: For Loops

I have explained it. All I want it to do is compute the answer. So If provide the arguments for e.g. 2 3 then it should be 2 to the power of 3 and should give an answer of 8. I just dont understand the for loop properly. Can someone explain what happens. The program is wrong it doesn't work.

Kind regards

Shyam

5. ## Re: For Loops

Have you worked out the problem on a piece of paper doing the math one operation on each line to see what the pattern is that you want in the loop?
What are the first two numbers to multiply
What are the next two
etc until done.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•