Princesden Princesden - 4 months ago 12
Java Question

Reprint a String array Java

I have a string array

"Ben", "Jim", "Ken"


how can I print the above array 3 times to look like this:

"Ben", "Jim", "Ken"
"Jim", "Ben", "Ken"
"Ken", "Jim", "Ben"


I just want each item in the initial array to appear as the first element. The order the other items appear does not matter.

more examples

Input

"a","b","c","d"


output

"a","b","c","d"
"b","a","c","d"
"c","b","a","d"
"d","a","c","d"


Method signature

public void printArray(String[] s){
}

Answer
public void printArray(String[] s){
    for (int i = 0; i < s.length; i++) {
        System.out.print("\"" + s[i] + "\",");
        for (int j = 0; j < s.length; j++) {
            if (j != i) {
                System.out.print("\"" + s[j] + "\",");
            }
        }
        System.out.println();
    }
}