Results 1 to 7 of 7
Thread: For loop error
- 04-04-2009, 07:35 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 14
- Rep Power
- 0
For loop error
I have been having some trouble with a for loop statement, here is my code:
And here is the error I get://Here is my multiplication table solution
public class MultiplicationTable
{
public static void main(String args[])
{
//Here I'll declare the variables and constants
final int MIN_ROW = 1;
final int MAX_ROW = 9;
final int MIN_COL = 2;
final int MAX_COL = 8;
int firstNumber = 2;
int secondNumber = 1;
int theAnswer = 0;
System.out.print("CSC-116 Homework Eight - Multiplication Table for N equals 2 through 8");
for (firstNumber >= MIN_COL; firstNumber <= MAX_COL; firstNumber++)
{
theAnswer = firstNumber * secondNumber;
++secondNumber;
System.out.print("Hello");
}
}
}
Thank you very much for your help.MultiplicationTable.java:21: not a statement
for (firstNumber >= MIN_COL; firstNumber <= MAX_COL; firstNumber++)
- 04-04-2009, 07:50 PM #2
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
The first part of a for loop is not a condition.
A common for loop may look like this:
You'll notice "int i = 0" initializes the counter to be used.Java Code:for(int i = 0; i < 10; i++) { //code }
Also, remember you can use the && (and) or || (or) to use multiple conditions,
Java Code:boolean example = true; for(int i = 0; i < 10 && example; i++) { //code }Last edited by AndrewM16921; 04-04-2009 at 07:53 PM.
- 04-04-2009, 08:58 PM #3
What loop should I use?
Iwant to set a loop but am not experienced enough to work out which kind.
I want to set a maximum of 12 records to be stored in a .txt file, should I be using a while loop?
- 04-04-2009, 09:06 PM #4
Member
- Join Date
- Feb 2008
- Location
- Oregon, USA
- Posts
- 49
- Rep Power
- 0
- 04-04-2009, 11:47 PM #5
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
No, you just take the ">" off the loop and that's should work )))Java Code:for (firstNumber >= MIN_COL; firstNumber <= MAX_COL; firstNumber++)
- 04-05-2009, 01:31 AM #6
OK, I'll try this, thanks
- 04-06-2009, 01:14 AM #7
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Similar Threads
-
Loop Help
By HeavyD in forum New To JavaReplies: 7Last Post: 09-22-2010, 09:55 PM -
help error in while loop
By iPetey in forum New To JavaReplies: 3Last Post: 04-03-2009, 03:56 AM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM -
error 530 error authentication required
By rgale in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-12-2008, 04:28 PM -
can you help me with this for loop?
By java_fun2007 in forum New To JavaReplies: 6Last Post: 12-22-2007, 10:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks