Advertisement
Hiteshw11

Sum And Avg Of Array

Jan 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.*;
  2. class SumAndAvg {
  3.     public static void main(String[] args) {
  4.         int n;
  5.         float c,sum=0;
  6.         Scanner src=new Scanner(System.in);
  7.         System.out.println("Enter the size of array");
  8.         n=src.nextInt();
  9.         int a[]=new int[n];
  10.         for(int i=0;i<n;i++)
  11.         {
  12.             System.out.println("Enter the element");
  13.             a[i]=src.nextInt();
  14.         }
  15.         System.out.println("The elements are");
  16.         for(int j=0;j<n;j++)
  17.         {
  18.             System.out.println(a[j]);
  19.         }
  20.         for(int k=0;k<n;k++)
  21.         {
  22.             c=a[k];
  23.             sum=sum+c;
  24.         }
  25.         System.out.println("The sum of the array is "+sum);
  26.         float avg=sum/n;
  27.         System.out.println("The avg of the array is "+avg);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement