-
-
Save mariiaKolokolova/7af9545303f1ad336d3920b88c9ba165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package maricka.kolokolova; | |
import java.util.Arrays; | |
public class Main { | |
public static void main(String[] args) { | |
int[] array = { 1, 2, 3, 4, 5 }; | |
combinations(array, array.length); | |
} | |
public static void combinations(int[] array, int size) { | |
int a; | |
for (int i = 0; i < size; i++) { | |
a = array[size - 1]; | |
for (int j = size - 1; j > 0; j--) { | |
array[j] = array[j - 1]; | |
} | |
array[0] = a; | |
if (size > 2) { | |
combinations(array, size - 1); | |
} | |
if (size == 2) { | |
System.out.println(Arrays.toString(array)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment