Answer to Question #286910 in Java | JSP | JSF for Ace

Question #286910

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.


1
Expert's answer
2022-01-13T16:11:58-0500
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog