This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes help me with this minor mistake Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help me with this minor mistake" Watch "help me with this minor mistake" New topic
Author

help me with this minor mistake

Erjan Kenjegalee
Greenhorn

Joined: Apr 19, 2010
Posts: 22

hi everyone, i am novice here))))



the thing is that Eclipse gives me a mistake in theAverage method - it underlines long[] y - i don't know why!
"syntax error misplaced constructs"

any suggestions?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18748
    
  40


I am assuming that it is at line 16? When you call a method, you don't need to declare the type of the variable that you are passing -- the compiler knows what it is.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Erjan Kenjegalee
Greenhorn

Joined: Apr 19, 2010
Posts: 22

thanks Henry!
it works ok now.

i also have one more question

why should i declare the method theAverage static?

it looks like all methods outside of static main method

must be declared static ? right?
can you explain it to me?
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
You should not declare your method static unless you are invoking it directly in a static context.
If you want to invoke it directly in main method (a static method), you must declare it as static

Look at the following use:



In the snippet of code your method theAverge has to be static, because i am invoking it inside a static method (the main method) directly.

But look at this:


now you create an object of class Operations_with_Array and you invoke the method theAverage on that object.
The method now is an instance method, not a static method.

Bye,
Nicola
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me with this minor mistake