Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Classe teste para ver os resultados das permutacoes.
- *
- * Autor: Daemonio (Marcos Paulo Ferreira)
- * Contato: undefinido gmail com
- * http://daemoniolabs.wordpress.com
- *
- * Qui Out 27 19:48:17 BRST 2011
- */
- package permutacao;
- /**
- *
- * @author daemonio
- */
- public class Main {
- public static void main(String[] args) {
- String[] str = {"uva", "pera", "laranja", "manga", "goiaba"};
- String[] saida;
- int i, j, r;
- /**
- * Primeiro parametro: O vetor de elementos
- * Segundo parametro: O tamanho de r. Esse tamanho
- * deve ser maior que zero.
- */
- r = 3 ;
- Permutacao p = new Permutacao(str, r);
- while_loop:
- while (p.hasNext()) {
- saida = p.next();
- /* Pesquisa no vetor 'saida' se ha elementos
- * identicos. Caso positivo, essa permutacao
- * e' ignorada.
- */
- for (i = 0; i < r; i++) {
- for (j = 1; j < r && i != j; j++) {
- if (saida[i].equals(saida[j])) {
- continue while_loop;
- }
- }
- }
- /* Mostra a permutacao na tela. */
- for (String e : saida) {
- System.out.print(e + ",");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment