Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Anagrama {
- public static void main(String[] args) {
- String palavra = JOptionPane.showInputDialog(null, "Insert text");
- String[] S = palavra.split(" ");
- char vetor[];
- int t;
- int u = Integer.parseInt(S[0]); // recebe a quantidade de palavras
- for(int i = 0; i < u; i++){ // repete o código para cada palavra
- vetor = new char[S[i].length()]; // coloca a palavra que será usada em um vetor
- for (int j = 0; j < S[i].length(); j++) {
- t = vetor.length; // recebe o tamanho da palavra que será usada
- for (int x = t; x > 0; x--) { // calcula a quantidade de anagramas que a palavra possui
- t = t * x;
- }
- for (int l = 0; l < t; l++) { // repete o código para cada anagrama da palavra
- System.out.println(vetor); // imprime o anagrama
- vetor[j] = S[i].charAt(l); // cria o próximo anagrama
- char aux;
- aux = vetor[l];
- vetor[l] = vetor[i];
- vetor[i] = aux;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement