Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:43:47+00:00 2026-06-15T17:43:47+00:00

I am having problem with my Search Method once the item i am searching

  • 0

I am having problem with my Search Method once the item i am searching for is shown in this case its the students details, it outputs the “else” option of the if statment, below is the code that is being used in this method

public  void search(String StudentlName)
{ 

    boolean found = true;   // set flag to true to begin first pass

    while ( found ==true )
    {

        for (int index = 0; index<= lName.length; index ++)
        {
            if (StudentlName.equalsIgnoreCase(lName[index])
            {
                System.out.println(course+"\n"+
                    "Student ID = \t"+index+"\n"+ 
                    unitTitle + "\n" +
                    fName[index] + "\n"  + 
                    lName[index] + "\n" + 
                    Marks[index] + "\n" + "\n" );
                found = false;
            }
            else
            {
                System.out.println("Student Not Found");
            }//End of If
        }// End of For
    }
}//end of search Method

This is part of my Menu Class,

        case 7:
                    System.out.println("Please Enter The Students
                                        you wish to find Last Name ");
                    String templName = keyb.nextLine();
                    System.out.println("");
                    myUnit.search(templName);
                    option = menuSystem();
                    break;

I figure its got something to do with the for loop but i cant get it through my head.

Once i type in the correct Surname (in this case “Scullion”) I want in this appears:

HND Computing
Student ID = 0
Java
Daniel
Scullion
60
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
10 Student Not Found
Student Not Found
Student Not Found
Student Not Found
Student Not Found Student Not Found Student Not Found Student Not
Found Student Not Found
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:43:47+00:00Added an answer on June 15, 2026 at 5:43 pm
      for (int index = 0; index<= lName.length; index ++)
    

    should be

      for (int index = 0; index<lName.length; index ++)
    

    Array indexes are zero based. i.e, they start index is 0 and the end-index is Arraylength-1.

    Example: for isntance your array is of length 10.

    start-Index—>0

    end-index—–>9

    If you try to access an index above 9, ArrayIndexOutOfBounds will be thrown at runtime.

    EDIT:

    use a break statement to break out of your for-loop once you have found the student.

    if (StudentlName.equalsIgnoreCase(lName[index])  )
    
          {
              System.out.println(course+"\n"+
                      "Student ID = \t"+index+"\n"+ 
                      unitTitle + "\n" +
                      fName[index] + "\n"  + 
                      lName[index] + "\n" + 
                      Marks[index] + "\n" + "\n" );
              found = false;
              break; //this will break outta the for-loop
          } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem I'm having is a search function which should call my doSearch() -method
I'm having trouble wording my problem to search for it, so if anyone could
I am having a small problem with the Magento quick search. When I search
I'm having trouble wording my problem, so it's been tough to search for an
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I am having problem to get a numerical value for this expression where I
I am having an odd problem when searching a UITableView using a UISearchDisplayController. The
im having a problem with the Select() method in my datatable. If i want
I am having a problem with the get_post method. Here is my code: <!DOCTYPE
I will preface this with I'm actively searching for the solution to this problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.