Advertisement
n_stefanov

Ex2_Generate3LetterWords

May 14th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. package javaLoopsMethodsClasses;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex2_Generate3LetterWords {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner in = new Scanner(System.in);
  10.         String input = in.next();
  11.         char[] givenLetters = input.toCharArray();
  12.  
  13.         findCombinations(givenLetters, "");
  14.     }
  15.  
  16.     public static void findCombinations(char[] givenLetters, String curr) {
  17.  
  18.         if (curr.length() == 3) {
  19.             System.out.println(curr);
  20.  
  21.         } else {
  22.             for (int i = 0; i < givenLetters.length; i++) {
  23.                 String oldCurr = curr;
  24.                 curr += givenLetters[i];
  25.                 findCombinations(givenLetters, curr);
  26.                 curr = oldCurr;
  27.             }
  28.         }
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement