Answer to Question #286927 in Java | JSP | JSF for Dragon

Question #286927

Write a program to store age of 50 persons in an array then display the frequency of teenagers between 15 to 35 using linear searching.


1
Expert's answer
2022-01-14T04:36:18-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		int ages[] = new int[50];
		for (int i = 0; i < ages.length; i++) {
			System.out.print("Enter the age of the person " + (i + 1) + ": ");
			ages[i] = keyBoard.nextInt();
		}
		int teenagers = 0;
		for (int i = 0; i < ages.length; i++) {
			if (ages[i] >= 15 && ages[i] <= 35) {
				teenagers++;
			}
		}
		System.out.println(teenagers + " teenagers are between 15 to 35 ");
		keyBoard.close();
	}
}

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