-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage array;.java
More file actions
40 lines (29 loc) · 789 Bytes
/
Copy pathpackage array;.java
File metadata and controls
40 lines (29 loc) · 789 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
38
39
40
package array;
import java.util.Scanner;
public class AnalyzeNumbers {
public static void main(String[] args) {
// 1. Take array size as input from user
Scanner input = new Scanner(System.in);
System.out.println("Enter the size of array: ");
int n = input.nextInt();
double[] numbers = new double[n]; // defining and creating the array
double sum = 0;
// 2. Intialisation of array
System.out.println("Enter the numbers: ");
for(int i=0; i<n; i++) {
numbers[i] = input.nextDouble();
sum += numbers[i];
}
// 3. Calculate average
double average = sum / n;
// 4. Find the number of elements greater than average
int count = 0;
for(int i=0; i<n; i++) {
if(numbers[i] > average) {
count++;
}
}
System.out.println("Average is: " + average);
System.out.println("Count is " + count);
}
}