Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import java.util.

Scanner;

class javaprogram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[][] students = new String[10][6];

for (int i = 0; i < students.length; i++) {


System.out.println("Enter Student ID " + (i+1) + ": ");
students[i][0] = scanner.nextLine();

System.out.println("Enter Last Name " + (i+1) + ": ");


students[i][1] = scanner.nextLine();

System.out.println("Enter First Name " + (i+1) + ": ");


students[i][2] = scanner.nextLine();

System.out.println("Enter Course " + (i+1) + ": ");


students[i][3] = scanner.nextLine();

System.out.println("Enter Year " + (i+1) + ": ");


students[i][4] = scanner.nextLine();

System.out.println("Enter Age " + (i+1) + ": ");


students[i][5] = scanner.nextLine();
}

System.out.println("Enter a Last Name : ");


String searchLastName = scanner.nextLine();
int lastNameCount = 0;

System.out.println("Enter a First Name : ");


String searchFirstName = scanner.nextLine();
int firstNameCount = 0;

for (int i = 0; i < students.length; i++) {


if (students[i][1].equalsIgnoreCase(searchLastName)) {
lastNameCount++;
}
if (students[i][2].equalsIgnoreCase(searchFirstName)) {
firstNameCount++;
}
}

System.out.println("Number of students with Last Name " + searchLastName +


": " + lastNameCount);
System.out.println("Number of students with First Name " + searchFirstName
+ ": " + firstNameCount);

System.out.println("Enter an Age: ");


String searchAge = scanner.nextLine();
int ageCount = 0;

for (int i = 0; i < students.length; i++) {


if (students[i][5].equals(searchAge)) {
ageCount++;
}
}
System.out.println("Number of students with Age " + searchAge + ": " +
ageCount);
}
}

You might also like