AlexKondov

Java Three Letter Words

May 15th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class GenerateThreeLetterWord {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         String characters = input.next();
  9.         char[] chars = characters.toCharArray();
  10.        
  11.         generateWords(chars);
  12.        
  13.     }
  14.     public static void generateWords(char[] chars) {
  15.         if (chars.length == 1) {
  16.             for (int i = 0; i < 3; i++) {
  17.                 System.out.println(chars[0]);              
  18.             }
  19.         }
  20.         else if (chars.length == 2) {
  21.             for (int i = 0; i < chars.length; i++) {
  22.                 for (int j = 0; j < chars.length; j++) {
  23.                     System.out.printf("%c%c", chars[i], chars[j]);
  24.                     System.out.println();
  25.                 }
  26.             }
  27.         }
  28.         else {
  29.             for (int i = 0; i < chars.length; i++) {
  30.                 for (int j = 0; j < chars.length; j++) {
  31.                     for (int h = 0; h < chars.length; h++) {
  32.                         System.out.printf("%c%c%c", chars[i], chars[j], chars[h]);
  33.                         System.out.println();
  34.                     }
  35.                 }
  36.             }          
  37.         }
  38.        
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment