import java.util.HashMap;
import java.util.Map;
public class AgeGenderStatistics {
public static void main(String[] args) {
// Create a map to store the age and gender of each person
Map<Integer, String> persons = new HashMap<>();
persons.put(34, "Male");
persons.put(20, "Female");
persons.put(40, "Male");
persons.put(25, "Female");
persons.put(30, "Male");
// Initialize the age and gender counters
int maleCount = 0;
int femaleCount = 0;
int totalAge = 0;
// Iterate through the map and update the counters
for (Map.Entry<Integer, String> entry : persons.entrySet()) {
int age = entry.getKey();
String gender = entry.getValue();
if (gender.equals("Male")) {
maleCount++;
} else if (gender.equals("Female")) {
femaleCount++;
}
totalAge += age;
}
// Calculate the average age of the group
double averageAge = (double) totalAge / persons.size();
// Print the age and gender statistics
System.out.println("Number of males: " + maleCount);
System.out.println("Number of females: " + femaleCount);
System.out.println("Average age: " + averageAge);
}
}