Write a program to create a single dimension array to store marks of 25 students. Then display the frequency of students in the range of marks:
0-30
31-50
51-75
76-90
91-100
Hint: 1)Use java.util package
2) Use linear searching
import java.util.*;
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
int marks[] = new int[25];
for (int i = 0; i < 25; i++) {
System.out.print("Enter the mark " + (i + 1) + ": ");
marks[i] = keyBoard.nextInt();
keyBoard.nextLine();
}
int frequency[] = new int[5];
for (int i = 0; i < 25; i++) {
if (marks[i] >= 0 && marks[i] <= 30) {
frequency[0]++;
}
if (marks[i] >= 31 && marks[i] <= 50) {
frequency[1]++;
}
if (marks[i] >= 51 && marks[i] <= 75) {
frequency[2]++;
}
if (marks[i] >= 76 && marks[i] <= 90) {
frequency[3]++;
}
if (marks[i] >= 91 && marks[i] <= 100) {
frequency[4]++;
}
}
System.out.println("0-30: " + frequency[0]);
System.out.println("31-50: " + frequency[1]);
System.out.println("51-75: " + frequency[2]);
System.out.println("76-90: " + frequency[3]);
System.out.println("91-100: " + frequency[4]);
keyBoard.close();
}
}
Comments
Leave a comment