0% found this document useful (0 votes)
12 views2 pages

Java Student Search Program

The document contains a Java program that allows users to input names and marks for 10 students. It then prompts the user to search for a specific student's name using linear search and displays the search result. The program handles input through the Scanner class and manages the search process with a boolean flag and an index position.

Uploaded by

annie
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Java Student Search Program

The document contains a Java program that allows users to input names and marks for 10 students. It then prompts the user to search for a specific student's name using linear search and displays the search result. The program handles input through the Scanner class and manages the search process with a boolean flag and an index position.

Uploaded by

annie
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;

public class StudentSearch {


public static void main(String[] args) {
// Create a scanner object for input
Scanner scanner = new Scanner([Link]);

// Arrays to store the names and marks of students


String[] students = new String[10];
int[] marks = new int[10];

// Input names and marks of 10 students


for (int i = 0; i < 10; i++) {
[Link]("Enter the name of student " + (i + 1) + ": ");
students[i] = [Link]();

[Link]("Enter the marks of " + students[i] + ": ");


marks[i] = [Link]();
[Link](); // Consume the newline character
}

// Input the name of the student to search for


[Link]("Enter the name of the student to search for: ");
String searchName = [Link]();

// Linear search for the name


boolean found = false;
int position = -1;

for (int i = 0; i < [Link]; i++) {


if (students[i].equalsIgnoreCase(searchName)) {
found = true;
position = i;
break;
}
}

// Display search result


if (found) {
[Link]("Search Successful");
[Link]("The student " + searchName + " is at position " + (position + 1) + " in the
array.");
} else {
[Link]("Search Unsuccessful");
}

// Close the scanner


[Link]();
}
}

You might also like