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 8961605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:55:56+00:00 2026-06-15T15:55:56+00:00

in the below code im searching for a surname in the lName array, once

  • 0

in the below code im searching for a surname in the lName array, once the surname is not found in the array the else output is showing for each time it is not found going round the loop, how would i go about solving this? if i add a return false statement in the else part it stops the loop after checking the first position of the array.

any help will be appriciated!

public boolean 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;

                return true;//Stops The Loop once Found used to stop infinite loop
            }
            else
            {
                System.out.println("Student Not Found");
            }
        }
        return false;
    }
    return true;  
}

If the result is not found this is shown output

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-15T15:55:58+00:00Added an answer on June 15, 2026 at 3:55 pm

    Print “Student not found” outside the loop, right before you return false. You only return false once, and by then you know you didn’t find the student; no “else” required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works when searching for any name that does not contain an
I am using the below code to close the window, by searching the window
I have Depth first searching algorithm whose pseudo code is given below: DFS(Vertex v)
Below code not work, but it's work fine for jsf1.2. Now the framework is
I tried half day on searching on the net already see my code below
Can someone PLEASE tell me why the below code is searching for sub folders
I have written the below code for recursively searching binary tree . Even though
After searching for posts regarding ScrollView not showing I couldn't find one example that
Why is the following algorithm not halting for me? In the code below, str
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,

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.