Write a program to create two arrays in order to store name and age of 15 persons. Then display only those names, whose age is between 10 to 30 and also display how many such records found.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] names = new String[15];
int[] ages = new int[15];
for (int i = 0; i < names.length; i++) {
names[i] = in.nextLine();
ages[i] = Integer.parseInt(in.nextLine());
}
int count = 0;
for (int i = 0; i < names.length; i++) {
if (ages[i] >= 10 && ages[i] <= 30) {
System.out.println(names[i]);
count++;
}
}
System.out.println(count);
}
}
Comments
Leave a comment