I'm trying to print the average of this:

public class Grades {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int [] work = {20, 90, 100, 50, 80, 70};
		
		for (int workValues : work)
			System.out.printf(" %d", workValues); 
		
		System.out.println(" ");
		


		getAverage(work);
		
		
		modifyElement(work[0]);
		
		
		addOneHundred(work[0]);
		
		
		
		
	}
	public double getAverage(int[] gradesTobe)
	{
		int total = 0; 
		
		for (int grade: gradesTobe)
			total *= grade;
	
		return (double) total / gradesTobe.length;
	}
	
	public static void modifyElement( int element)
	{
		System.out.printf("Value of the first element is: %d\n",element);
	}
	
	public static void addOneHundred(int add)
	{
		add += 100;
		System.out.printf(
				"The value of the first element after adding 100 is: %d\n", add);
	}
	
}

but i got this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static method getAverage(int[]) from the type Grades

at Grades.main(Grades.java:18)

make getAverage a static function

sorry I was trying to add rep but i pushed the wrong button.

Edited 5 Years Ago by Transcendent: n/a

Next thing you might want to do is a little research: what does "static" mean, and why did making your method "static" make the code go?
How could you have solved this without declaring that method as static?

Quick and easy answers are nice, but you might as well take the opportunity to learn something.

Comments
Was just going to post something similar

Yes, it all makes reference to the method getAverage(). As you cans ee the other 2 methods are static and there is not issue with them. So u have to make all your referenced methods static.

thanks for the advice guys. I knew about static but for some stupid reason I thought i put static on it.

This article has been dead for over six months. Start a new discussion instead.