Question: What am I doing wrong that the program returns zero as the sum? This is a program in java. User inputs 10 numbers and then

What am I doing wrong that the program returns zero as the sum? This is a program in java. User inputs 10 numbers and then there is a method call to sum those numbers.

package summ;

import java.util.*;

import java.util.Scanner;

public class summ

{

public static void main(String[] args)

{

int [] num = new int [10];

Scanner input = new Scanner(System.in);

System.out.println("Input ten integers:");

for (int i=0 ; i < num.length; i++)

num[i]= input.nextInt();

sumNum(num);

}

public static int sumNum (int[] list)

{

int sum=0;

System.out.println("The sum of the array is " + sum);

for (int i=0; i<= list.length-1; i++) {

sum += list[i];

}

return sum;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!