Womuse1979 Womuse1979 - 1 year ago 70
Java Question

Error passing int arrays to method Total

I am new to coding and so simple mistakes aren't very oblivious to me.
The code is trying to pass an integer of arrays into the method called total and if the array is empty return zero. My eclipse crashed and so I have to use an online tool to run my java code.

It keeps saying that I have an error and I do not understand its reasoning.

non-static method total(int[]) cannot be referenced from a static context

public static void main(String []args){
int [] array = {1,2,3,4};


public int total(int[] a){
if(a== null){
return 0;
int result=0;
for(int i = 0; i<a.length;i++){

return result;


Answer Source

change public int total(int[] a){ to public static int total(int[] a){

use System.out.println(total(array)); as call

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download