Results 1 to 6 of 6
- 12-08-2011, 07:19 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
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; } } }
- 12-08-2011, 08:41 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 90
- Rep Power
- 0
Re: problem showing array's elements with the same value
I don't understand what you're asking...
- 12-08-2011, 08:49 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
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.
- 12-08-2011, 09:01 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 90
- Rep Power
- 0
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?
- 12-08-2011, 09:07 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
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
- 12-08-2011, 09:21 PM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 10
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
-
searching one elements of array into another array???
By hacikho in forum New To JavaReplies: 3Last Post: 11-25-2011, 01:38 AM -
Problem with shifting array elements
By holy.water in forum New To JavaReplies: 4Last Post: 02-25-2011, 09:56 PM -
Why is my array of images not showing up?
By CNew in forum New To JavaReplies: 32Last Post: 12-12-2010, 04:57 AM -
sum of elements in array
By myst in forum New To JavaReplies: 7Last Post: 07-17-2010, 09:36 AM -
PROBLEM - calculating with array elements
By ella in forum New To JavaReplies: 13Last Post: 12-04-2008, 01:36 AM
Bookmarks