Write a program to store mark of 30 students out of 100 in computer then display how many students got 100 out of 100 using linear searching.
Hint: Use single dimension array.
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 counter=0, i, j;
int[] studentsMarks = new int[30];
for (i = 0; i < studentsMarks.length; i++) {
System.out.print("Enter the student mark " + (i + 1) + ": ");
studentsMarks[i] = keyBoard.nextInt();
}
for (i = 0; i < studentsMarks.length; i++) {
if (studentsMarks[i] == 100) {
counter++;
}
}
System.out.printf("%d students got 100 out of 100\n", counter);
keyBoard.close();
}
}
Comments
Leave a comment