Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class Anagrama {
  3.  
  4. public static void main(String[] args) {
  5. String palavra = JOptionPane.showInputDialog(null, "Insert text");
  6. String[] S = palavra.split(" ");
  7. char vetor[];
  8. int t;
  9. int u = Integer.parseInt(S[0]); // recebe a quantidade de palavras
  10. for(int i = 0; i < u; i++){ // repete o código para cada palavra
  11. vetor = new char[S[i].length()]; // coloca a palavra que será usada em um vetor
  12. for (int j = 0; j < S[i].length(); j++) {
  13. t = vetor.length; // recebe o tamanho da palavra que será usada
  14. for (int x = t; x > 0; x--) { // calcula a quantidade de anagramas que a palavra possui
  15. t = t * x;
  16. }
  17. for (int l = 0; l < t; l++) { // repete o código para cada anagrama da palavra
  18. System.out.println(vetor); // imprime o anagrama
  19. vetor[j] = S[i].charAt(l); // cria o próximo anagrama
  20. char aux;
  21. aux = vetor[l];
  22. vetor[l] = vetor[i];
  23. vetor[i] = aux;
  24. }
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement