Results 1 to 5 of 5
  1. #1
    david185000 is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default problem searching for a String element in a paralell array

    Hi guys

    I have a parallel array of 5 team names and 5 scores

    The user enters a team to search for and it is stored in the variable team

    this is my code

    String team;
    int loopcount;

    System.out.println("Please enter the team you would like to search for: ");
    team = input.next(); // identify team to be searched for





    for(loopcount = 0; loopcount < 5; loopcount++)
    {

    if (teaminfo[0][loopcount].equals(team) ) {
    System.out.println("Search has found : " + teaminfo[0][loopcount] + " at position: " + (loopcount+1));
    }

    }

    However when for some reason the for loop does not seem to be functioning. Have a made a glaring obvious newbie error?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    the for loop does not seem to be functioning.
    To see if it is functioning, add a println() inside of the loop to report progress.
    Or add an else clause and have it report that the if test was false.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

  4. #4
    Dan Penny's Avatar
    Dan Penny is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default

    You need to declare the type for loopcount. Use

    for (int loopcount=0; loopcount < 5; loopcount++)

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    There is no missing declare for loopcount. Otherwise the compiler would show it.
    See second line of posted source.

Similar Threads

  1. Searching for a String within an linked list
    By phil128 in forum Advanced Java
    Replies: 5
    Last Post: 04-13-2009, 02:18 AM
  2. Replies: 1
    Last Post: 03-31-2009, 06:40 AM
  3. [SOLVED] Searching a string in a vector
    By coolFrenzi in forum Advanced Java
    Replies: 5
    Last Post: 02-22-2009, 12:53 AM
  4. Searching In a String Array - Problem
    By DillMan in forum New To Java
    Replies: 4
    Last Post: 12-07-2008, 09:12 PM
  5. Searching a String from Text file using Swings .
    By pradeep1_mca@yahoo.com in forum AWT / Swing
    Replies: 4
    Last Post: 09-09-2008, 05:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •