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.
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();
}
}
Comments
Leave a comment