Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Its when I try to do stuff like this I realise I really need to go to university!

Anyway I have an array of strings (275) I need to loop through them and create strings of all the possible pairs, in Java.

I've been learning about recursion but I cant find the answer for this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
302 views
Welcome To Ask or Share your Answers For Others

1 Answer

In case pairs ab and ba are different, do:

for i=0 to array.length
  for j=0 to array.length
    if i == j skip
    else construct pair array[i], array[j] 

and if not, do something like this:

for i=0 to array.length-1
  for j=i+1 to array.length
    construct pair array[i], array[j] 

Note that I am assuming the array holds unique strings!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...