• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with the getElementAT()?  RSS feed

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The Error messages


C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: '.class' expected
return int ele = a[i][r];
^
C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: illegal start of expression
return int ele = a[i][r];
^
C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: ']' expected
return int ele = a[i][r];
^
C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: illegal start of expression
return int ele = a[i][r];
^
C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: ';' expected
return int ele = a[i][r];
^
C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: not a statement
return int ele = a[i][r];
^
C:\Java\Books\TheJavaProgrammingLanguage\Chapter02\Matrix.java:36: ';' expected
return int ele = a[i][r];
^
7 errors

Tool completed with exit code 1

[ November 10, 2008: Message edited by: Varuna Seneviratna ]
[ November 10, 2008: Message edited by: Varuna Seneviratna ]
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as the error messages suggest, the line

return int ele=a[i][r];

is horribly wrong. It seems like you're trying to do two things at once here: return a value, and declare a variable. You definitely can't do both of these on the same line of code. I think you're just trying to say something like

return a[i][r];

which should fix things.

Now, given that, let's look at your getElementAt() method. What exactly are you searching for? If the indices are within the correct range, then you can immediately return the value at those indices; the "for" loops are completely unnecessary. So, for example, why not just have this?



If the indices are invalid, you'll simply get an ArrayIndexOutOfBoundsException, which is a perfectly fine way to design things.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!