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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:22:18+00:00 2026-06-13T11:22:18+00:00

Sorry about the formatting disaster, I’m new to stackoverflow and Java. I have two

  • 0

Sorry about the formatting disaster, I’m new to stackoverflow and Java. I have two issues inside of a code that is supposed to contain two lists of names and corresponding catalog #s. Inside the code I am supposed to be able to search, display, edit, and quit. Display and quit already work, but I have an issue with search and edit. I have highlighted information where the issue is. I would appreciate any help.

public static void Search(String[] arr, String find) {

    for (int i = 0; i < 10; i++) {

//First issue!! This is my method to call upon later that searches within a String Array for bits of code. I need to be able to search within the array for certain characters (the arrays are names, so “mith” would bring up “smith”. Later in the code I call on this inside of a switch. I think I need something like “arr[i].equals(find)” but I can’t figure out the syntax

   }
}

public static void main(String[] args) {

    Scanner inp = new Scanner(System.in);
    String userInput1 = "";
    String userInput2 = "";
    String userInput3 = "";

    // Ask User to chose between faculty and students
    System.out.println("Are you searching for Students or Faculty? ");
    userInput1 = inp.nextLine().toLowerCase();


    if (userInput1.startsWith("f")) {

        //Block 1 for faculty
        do {

            String[] Faculty = {"0. Jack Kerouac", "1. Les Claypool", "2. Tom Waits", "3. Kurt Vonnegut",
                "4. Hunter Thompson", "5. Princess Bubblegum", "6. John Smith", "7. Jack Thompson", "8. Jeff Dahmer", "9. Martin King"};


            System.out.println("What would you like to do?");
            System.out.println("S: Search");
            System.out.println("E: Edit");
            System.out.println("D: Display");
            System.out.println("Q: Quit");

            // user input
            userInput2 = inp.nextLine().toLowerCase();
            System.out.println("");

            // Respond based on user input
            switch (userInput2.charAt(0)) {
                case 's':
                    System.out.println("Type part of the persons name: ");
                    String x = inp.nextLine().toLowerCase();
                    String[] y = Faculty;
                    Search(y, x);
                break;
                case 'e':

//This is my editing arrays issue comes in. I’ve attempted a couple different methods to get this to work but in each one I run into a problem when reassigning the Faculty[q]. When you run the program it skips from “Enter new catalog information” back to the main loop. How do I change the string inside of my array?

                    System.out.println("Enter the catalog number of the entry trying to edit: ");
                    int q = inp.nextInt();
                    System.out.println(Faculty[q]);
                    System.out.println("Enter new catalog information: ");                       
                    String NewFac = inp.nextLine();
                    Faculty[q] = String NewFac;
                    System.out.println(Faculty[q]);

                    break;
                case 'd':
                    System.out.println("Enter a catalog number between 0-9: ");
                    int o = inp.nextInt();
                    System.out.println(Faculty[o]);
                    break;

            }

            // Blank line, for formatting
            System.out.println("");

        } while (!userInput2.equals("q"));
        System.out.println("Done.");


    } else {
        //block 2 for students
        do {

            String[] Student = {"0. Alice Johnson", "1. Johnny Marr", "2. Johnny Johnson", "3. Robert Smith",
                "4. Ian Curtis", "5. Luke Shapiro", "6. David Newman", "7. Ren Newman", "8. Camille Kaslan", "9. Alexander Shulgin"};

            System.out.println("What would you like to do?");
            System.out.println("S: Search");
            System.out.println("E: Edit");
            System.out.println("D: Display");
            System.out.println("Q: Quit");

            // user input
            userInput3 = inp.nextLine().toLowerCase();
            System.out.println("");

            // Respond based on user input
            switch (userInput3.charAt(0)) {
                case 's':
                    System.out.println("Type part of the persons name: ");
                    String x = inp.nextLine().toLowerCase();
                    String[] y = Student;
                    Search(y, x);
                break;
                case 'e':
                    System.out.println("Enter the catalog number of the entry trying to edit: ");
                    int r = inp.nextInt();
                    System.out.println(Student[r]);
                    System.out.println("Enter new catalog information: ");
                    Student[r] = inp.nextLine();
                    System.out.println(Student[r]);
                    break;
                case 'd':
                    System.out.println("Enter a catalog number between 0-9: ");
                    int n = inp.nextInt();
                    System.out.println(Student[n]);
                    break;

            }

            // Blank line, for formatting
            System.out.println("");

        } while (!userInput3.equals("q"));
        System.out.println("Done.");



    }

In case it was unclear, the firsts issue is what to put in the for-loop inside of my search method called “search”. The second question is how to take the new info from the user and replace it in the array of names (the edit feature).

  • 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-13T11:22:19+00:00Added an answer on June 13, 2026 at 11:22 am

    First question, maybe something like this?

    public static void Search(String[] arr, String find) {
        for (int i = 0; i < 10; i++) {
            if (arr[i].toLowerCase().contains(find.toLowerCase())) {
                 System.out.println(String.format("found name: %s", arr[i]));
                 return;
            }
        }
        System.out.println("Name not found!");
    }
    

    Second question is a common problem that comes up all the time on SO, you need to follow your nextInt with a nextLine to eat the newline character:

    System.out.println("Enter the catalog number of the entry trying to edit: ");
    int q = inp.nextInt();
    inp.nextLine();
    System.out.println(Faculty[q]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry about input mistakes, english its not my mother lang. I have this code
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
Sorry about the wording for my question title. I have a basic HTML anchor
I have such class (sorry about posible mistakes, i'm writing it right here.) Class
I have two tables, splits and dividends that describe events in the stock market.
Sorry about the title. That was the best I could come up with. Anyways,
Sorry about the confusing title, I am newbie and have no idea what to
sorry about the funky title, I was having trouble coming up with one. First
Sorry about the stupid question however I can't see/ not good enough to solve
Sorry about the wording of the question, I don't really know how to put

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.