-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumAverage.java
More file actions
37 lines (37 loc) · 779 Bytes
/
Copy pathSumAverage.java
File metadata and controls
37 lines (37 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
*A Java program to read N numbers using Array and calculate
their sum and average
*/
import java.util.Scanner;
class SumAverage
{
public static void main(String args[])
{
int i,n,s=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the size of Array:");
n=sc.nextInt();
int arr[]=new int[n];
//Input
System.out.println("Enter "+n+" elements:");
for(i=0;i<n;i++)
{
System.out.print("N"+(i+1)+"=");
arr[i]=sc.nextInt();
}
//Process
for(i=0;i<n;i++)
{
s=s+arr[i];
}
double av=(double)s/n;
//Output
System.out.println("The elements of array are:");
for(i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println("\nSum="+s);
System.out.println("Average="+av);
}
}