Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying a 2dimensional array  RSS feed

 
Peter Merker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I tried to compile the following code but got an error for "i" where commented.

What is wrong?
Peter
[ October 26, 2003: Message edited by: Peter Merker ]
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
please pay attention to the ";" right after the for loop, this ; signifies
end of the for loop right there. Therefore, the i inside sebsequent curly block can not be resolved.
void printMatrix(int[][] m)
{
for(int i=0; i<m.length; i++); // ; here
{
printElement(m[i]); // cannot resolve symbol :
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You've got a stray semicolon at the end of this line; it serves as the loop body, so the block where the error is is outside the loop and there's no "i" declared.
 
Peter Merker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chi and Ernest, thank you both!
I guess I'm spending too much time trying to learn Java and not enough in bed... Couldn't figure this out for more than an hour!
 
William Barnes
Ranch Hand
Posts: 1049
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another good example of why you should always use curly braces, even if you only have one line of code.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!