Created
September 21, 2015 14:46
-
-
Save Pyroarsonist/fa863e25d059e3a1d1d1 to your computer and use it in GitHub Desktop.
3)Существует массив {1,2,3,4,5}. Напишите программу которая выведет на экран все возможные комбинации из этих цифр. Внимание повторений быть не должно.(2 часа)
This file contains hidden or 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 lvl2c; | |
| import java.util.Arrays; | |
| public class Main { | |
| public static void main(String[] args) { | |
| int[] A = new int[] {1,2,3,4,5}; | |
| comb(A,0); | |
| } | |
| static void comb(int[] A, int i) { | |
| if (i == A.length - 1) { | |
| System.out.println(Arrays.toString(A)); | |
| } else { | |
| for (int j = i; j < A.length; j++) { | |
| change(A, i, j); | |
| comb(A, i + 1); | |
| change(A, i, j); | |
| } | |
| } | |
| } | |
| static void change(int[] A, int i, int j) { | |
| int z = A[i]; | |
| A[i] = A[j]; | |
| A[j] = z; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment