Write a Program in java which creates the array of size 5, find the sum and average of the five numbers.

Write a Program in java which creates the array of size 5, find the  sum and average of the five numbers.



import java.util.*;

class SumAvg_Array

{

 public static void main(String arg[])

 {

   int sum=0;

   double avg;

   Scanner scr= new Scanner(System.in);

   int arr[]=new int[5];

   System.out.println("enter values in the array:");

   for(int i=0;i<5;i++)

   {

    arr[i]=scr.nextInt();

    sum=sum + arr[i];

   }

   avg= sum/5.0;  

   System.out.println("Sum of Array Elements are:"+sum);

   System.out.println("Average of Array Elements : " +avg);

 }

}

Output





Post a Comment

0 Comments