Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Variations {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int length = Integer.parseInt(scanner.nextLine());
- String[] pair = scanner.nextLine().split("\\s+");
- printAllVariations(pair, "", length);
- }
- private static void printAllVariations(String[] pair, String currVariation, int length) {
- if(length == 0) {
- System.out.println(currVariation);
- return;
- }
- for (int i = 0; i < pair.length; i++) {
- String newVariation = currVariation + pair[i];
- printAllVariations(pair, newVariation, length - 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment