Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class SumAndAvg {
- public static void main(String[] args) {
- int n;
- float c,sum=0;
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the size of array");
- n=src.nextInt();
- int a[]=new int[n];
- for(int i=0;i<n;i++)
- {
- System.out.println("Enter the element");
- a[i]=src.nextInt();
- }
- System.out.println("The elements are");
- for(int j=0;j<n;j++)
- {
- System.out.println(a[j]);
- }
- for(int k=0;k<n;k++)
- {
- c=a[k];
- sum=sum+c;
- }
- System.out.println("The sum of the array is "+sum);
- float avg=sum/n;
- System.out.println("The avg of the array is "+avg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement