Results 1 to 2 of 2
- 05-28-2014, 10:14 PM #1
Member
- Join Date
- Apr 2014
- Location
- Miami, FL
- Posts
- 47
- Rep Power
- 0
Why won't this variable increment!
I am trying to increment a variable named counterVariable each time it goes through a for enhanced loop. It is stuck on 0. Could someone explain why and how to fix this?
Java Code:valuesProcessor: for(String[] row : values) { for(String col : row) { int counterVariable = 0; if(col == null) break valuesProcessor; else if(counterVariable == 0) System.out.printf("%s", col); else if(counterVariable == 1) System.out.printf("%10s", col); else if(counterVariable == 2) System.out.printf("%130s", col); else if(counterVariable == 3) System.out.printf("%1330s", col); System.out.print(" "); counterVariable++; } System.out.println(); }
- 05-28-2014, 10:29 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Why won't this variable increment!
Well, for one thing, you keep resetting it to 0 in the inner loop. And to complicate matters, when you exit the inner loop, the variable goes out of scope.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Post increment
By bigo005 in forum New To JavaReplies: 5Last Post: 01-11-2014, 02:58 AM -
Date increment help
By jeffrey159 in forum New To JavaReplies: 0Last Post: 10-18-2013, 03:19 PM -
Increment Counter for ID
By blkshrk81 in forum New To JavaReplies: 6Last Post: 12-01-2010, 01:25 AM -
Increment Operator Example
By abimaran in forum New To JavaReplies: 10Last Post: 11-03-2009, 04:45 PM -
Increment a Variable
By rhm54 in forum New To JavaReplies: 2Last Post: 06-14-2008, 02:57 AM
Bookmarks