Results 1 to 5 of 5
Thread: For Loops
- 09-27-2011, 05:02 PM #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:
Can anyone help on correcting this problem and possibly explaining how the for loop works, because i'm so confused :SJava Code:public class Power { public static void main(String [] args) { int number = Integer.parseInt(args[0]); int power = Integer.parseInt(args[1]); int answer = 0; for (int i = 0; i*i < power; i++) answer=number*power; System.out.println(answer); } }
Kind regards
Shyam
- 09-27-2011, 05:16 PM #2
Re: For Loops
Can you explain what the problem is?help on correcting this problem
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.
- 09-27-2011, 05:22 PM #3
Re: For Loops
Guess you didn't like the answer you already got?
Crossposted: For LoopsHow to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 09-27-2011, 09:36 PM #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
- 09-27-2011, 09:41 PM #5
Similar Threads
-
[Semi-Beginner] (nested loops) What's wrong with my code? (nested loops)
By Solarsonic in forum New To JavaReplies: 20Last Post: 03-22-2011, 04:02 AM -
Help with Loops
By Spyderpig in forum New To JavaReplies: 10Last Post: 02-17-2011, 08:10 AM -
loops
By curioustoknow in forum New To JavaReplies: 3Last Post: 02-06-2011, 01:45 PM -
Help with loops
By pg5678pg in forum New To JavaReplies: 8Last Post: 10-17-2010, 06:51 PM -
when should we use loops
By shahemaan in forum New To JavaReplies: 1Last Post: 10-31-2009, 01:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks