• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying a 2dimensional array

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic