KenDoBG

Untitled

Jan 9th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5.  
  6. public class SuperSet {
  7.  
  8.         public static int[] numberArray;
  9.         public static int[] newNumberArray;
  10.         public static int start;
  11.         public static int end;
  12.         public static boolean[] used;
  13.  
  14.         public static void main(String[] args) throws IOException {
  15.             BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  16.  
  17.             numberArray = Arrays.stream(reader.readLine().split(", "))
  18.                     .mapToInt(Integer::parseInt)
  19.                     .toArray();
  20.  
  21.  
  22.             start = 0;
  23.             end = numberArray.length;
  24.  
  25.             for (int i = 1; i <= end; i++) {
  26.                 newNumberArray = new int[i];
  27.                 combination(0, start, i);
  28.             }
  29.  
  30.  
  31.         }
  32.  
  33.         private static void combination(int index, int start, int limit) {
  34.             if (index == limit) {
  35.                 printArray();
  36.                 return;
  37.             }
  38.             for (int i = start; i < end; i++) {
  39.                 newNumberArray[index] = numberArray[i];
  40.                 combination(index + 1, i + 1, limit);
  41.             }
  42.         }
  43.  
  44.  
  45.         private static void printArray() {
  46.             for (int n : newNumberArray) {
  47.                 System.out.print(n + " ");
  48.             }
  49.             System.out.println();
  50.         }
  51.     }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment