Results 1 to 6 of 6
  1. #1
    Shien is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default problem showing array's elements with the same value

    Lets say I have two arrays with values {A, B, D, F, B, S} and {B, D, F, K, S, M}
    In the programs GUI I have one textfield to input letter and two textareas to output arrays.
    I wrote code for button, that reads string from textfield and searches for same value in first array. If it's found puts it in the first array and same index value from another array into next texArea.
    My code can write a chain. If in the first array is another same value it should also show it. But this is the problem, I don't know how to write the code for it. I tried to read about maze algorythms but it didn't helped.

    Java Code:
    for(int i = 0; i < counter; i++)
                        {
                            fta = iArray[i];
                            sta = tArray[i];
                            if(sequence.equals(fta))
                            {
                                textArea1.append(fta+"\n");
                                textArea2.append(sta+"\n");
                                oldsta = sta;
                            }
                            else if(fta.equals(oldsta))
                            {
                                textArea1.append(fta+"\n");
                                textArea2.append(sta+"\n");
                                oldsta = sta;
                            }
                            else{
                                if(i>0)
                                
                                 loop:
                                 for(int k = i-1; k < counter; k++)
                                 {
                                     if(fta.equals(iArray[k]))
                                     {
                                        textArea1.append(iArray[i]+"\n");
                                        textArea2.append(tArray[i]+"\n");
                                        oldsta = tArray[i];
                                        break loop;
                                    }
                                 }
                                }
    Any ideas how to fix it?

  2. #2
    joeyvitoro is offline Member
    Join Date
    Oct 2011
    Posts
    90
    Rep Power
    0

    Default Re: problem showing array's elements with the same value

    I don't understand what you're asking...

  3. #3
    Shien is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: problem showing array's elements with the same value

    Think about treeWidget. if one element has two branches it shows it. That's what I have to do.

    I hope that you do understand. English aren't my native language.

  4. #4
    joeyvitoro is offline Member
    Join Date
    Oct 2011
    Posts
    90
    Rep Power
    0

    Default Re: problem showing array's elements with the same value

    I'm afraid I don't know what treeWidget is. Can you give me a use case? What do you input, and what are you expecting as an output?

  5. #5
    Shien is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: problem showing array's elements with the same value

    Ok. As I said before I have two arrays: arr1 = {A, B, D, F, B, S} and arr2 = {B, D, F, K, S, M}
    I enter string A. So now I see this:
    A - B
    B - D
    D - F
    F - K

    But there is another value B which should also be seen. That the problem. I don't know how to show it.

    It should be like:
    A - B
    B - D
    D - F
    F - K
    B - S
    S - M

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: problem showing array's elements with the same value

    Record the postion in the array of the found input e.g. if input was "D" then the position in the array is 2. Then write a for loop that will loop from that position to the end of the array printing out the letter at each index of the array to each textarea.

    psuedo
    for ( i = position; i<array length; i++)
    print array1[i] to textarea1
    print array2[i] to textarea2

Similar Threads

  1. Replies: 3
    Last Post: 11-25-2011, 01:38 AM
  2. Problem with shifting array elements
    By holy.water in forum New To Java
    Replies: 4
    Last Post: 02-25-2011, 09:56 PM
  3. Why is my array of images not showing up?
    By CNew in forum New To Java
    Replies: 32
    Last Post: 12-12-2010, 04:57 AM
  4. sum of elements in array
    By myst in forum New To Java
    Replies: 7
    Last Post: 07-17-2010, 09:36 AM
  5. PROBLEM - calculating with array elements
    By ella in forum New To Java
    Replies: 13
    Last Post: 12-04-2008, 01:36 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
  •