Advertisement
Guest User

Untitled

a guest
May 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. package Algorithms.recursion;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. /**
  8. * Created by Ruslan Zhdan on 30.05.2016.
  9. */
  10. public class AnagramApp
  11. {
  12. static int size;
  13. static int count;
  14. static char[] arrCharr = new char[100];
  15.  
  16.  
  17. public static void main(String[] args) throws IOException
  18. {
  19. System.out.print("Enter a word: ");
  20. String input = getString();
  21. size = input.length();
  22. count = 0;
  23. for (int j = 0; j < size; j++)
  24. arrCharr[j] = input.charAt(j);
  25. doAnagram(size);
  26. }
  27.  
  28. public static void doAnagram (int newSize)
  29. {
  30. if (newSize == 1)
  31. return;
  32. for (int j = 0; j < newSize; j++){
  33. doAnagram(newSize-1);
  34. if (newSize == 2)
  35. displayWord();
  36. rotate(newSize);
  37. }
  38. }
  39.  
  40. public static void rotate(int newSize)
  41. {
  42. int j;
  43. int position = size - newSize;
  44. char temp = arrCharr[position];
  45. for (j = position+1; j < size; j++)
  46. arrCharr[j-1] = arrCharr[j];
  47. arrCharr[j-1] = temp;
  48. }
  49.  
  50. public static void displayWord()
  51. {
  52. if (count < 99)
  53. System.out.print(" ");
  54. if (count < 9)
  55. System.out.print(" ");
  56. System.out.println(++count + " ");
  57. for (int j = 0; j < size; j++)
  58. System.out.print(arrCharr[j]);
  59. System.out.print(" ");
  60. System.out.flush();
  61. if (count % 6 == 0)
  62. System.out.println("");
  63. }
  64.  
  65. public static String getString() throws IOException
  66. {
  67. InputStreamReader isr = new InputStreamReader(System.in);
  68. BufferedReader br = new BufferedReader(isr);
  69. String s = br.readLine();
  70. return s;
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement