A simple program that I wrote in Java to find the sum and average of numbers using one dimensional array in Java. What the program does it will ask the user to give a series of integer number and then the program will compute the sum and average of the five numbers given by the user of our program.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
sum_array.java
package hello;
import java.util.Scanner;
public class sum_array {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int num[]=new int[5];
int average=0,i=0,sum=0;
System.out.println("Sum and Average of Numbers Using Array in Java");
System.out.println();
for (i=0;i<num.length;i++) {
System.out.print("Enter a Number : ");
num[i]=input.nextInt();
sum=sum+num[i];
}
average=(sum/5);
System.out.println();
System.out.println("The total sum is "+ sum + ".");
System.out.println();
System.out.println("The average is "+average+".");
System.out.println();
System.out.println("\t End of Program");
}
}