-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayAge.java
More file actions
26 lines (22 loc) · 768 Bytes
/
Copy patharrayAge.java
File metadata and controls
26 lines (22 loc) · 768 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
import java.util.Scanner;
public class arrayAge {
public static void main(String[] args) {
int[] age = new int[10];
int sum = 0;
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
System.out.print("Enter age of person " + (i + 1) + ": ");
age[i] = sc.nextInt();
sum += age[i];
}
int average = sum / 10;
System.out.println("The average age is: " + average + " years old.");
System.out.println("The ages of the people between 25 and 30 are : ");
for (int i = 0; i < 10; i++) {
if (age[i] >= 25 && age[i] <= 30) {
System.out.println(age[i] + " years old.");
}
}
sc.close();
}
}