0

What i'm trying to achieve is that, I have an array,

for eg: a={1,2,3}

Now, I need an array which combines all the elements in the array.

ie, the output that is needed should be like.

{[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]}

I know that, in StackOverflow asking a question without showing what I have done is not at all appreciated, but still, I'm totally blank and i dont have any ideas to code this. Any help is very much appreciated.

2 Answers 2

2

To generate the resulting array, use two loops, one nested inside the other, both using indexes (say, i and j) going from 0 through < length on the array. The two values for the resulting element in the new array come from a[i] and a[j].

Sign up to request clarification or add additional context in comments.

Comments

1

What I think it's to make a double loop. Like this:

for(int i = 0; i < array.length; i++)
{
   for (int j = 0; j < array.length; j++)
   {
      System.out.println("[" + array[i] + "," + array[j] + "]");
   }
}

2 Comments

In general, best to reply to these kinds of questions with teaching rather than a code dump
@T.J.Crowder Yes, I usually don't post code for this kind of questions but, in this case, it would be equals to put "You have to use 2 loops" that to put the code above. Anyway, thanks for alert to me ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.