I need you to display the text string on the screen are permutations without repetition

0
import java.util.Scanner;
import java.util.Vector;

public class Permuatciones
{
    static String cadena="";
    static int factorial=0;
    static Vector permutacion = new Vector();
    public static void main(String[] args) 
   {
            Scanner meter = new Scanner(System.in);
            System.out.println("Introduzca una cadena");
            cadena = meter.nextLine(); 

    boolean repit=false;

    for (int i=0;i<cadena.length();i++)
    {
        int cont=0;
        for(int j=0; j<cadena.length(); j++)
        {
            if(cadena.charAt(j) == cadena.charAt(i))
            {
                cont++;
            }

        }
        if(cont>1)
        {
      repit=true;
        }
    }
     if (repit==true)
        {
            System.out.println("La cadena tiene carateres repetidos");
            System.exit(0);
        }          
        else if(repit==false)
            {
            factorial();
            for(int i=0; i<permutacion.size(); i++)
            {
            System.out.println(i+1);
            }

            }  
    }
    public static void factorial()
    {
        factorial=cadena.length();
        for (int i=cadena.length()-1; i>0 ; i--)
        {
            factorial*=i;
        }


permutar();
    }
    public static void permutar()
    {
        for(int i=0; i<factorial; i++)
        {
            int arreglo[] = new int[cadena.length()];
            for(int j=0; j<arreglo.length; j++)
            {
                arreglo[j]=-1;
            }
            for(int j=0; j<arreglo.length; j++)
            {
                boolean continuar = true;

                do
                {
                  boolean repit=false;

                int random =(int) Math.rint(Math.random()*(cadena.length()-1));

                for(int m=0;m<arreglo.length; m++)
                {
                    if(random==arreglo[m])
                    {
                        repit=true;
                    }
                    if(repit==true)
                    {
                        continuar=true;
                    }
                    else if(repit==false)
                    {
                        arreglo[j]=random;
                        continuar = false;
                    }

                }
                 }while(continuar);

            }

           String temp="";

          for(int j=0; j<arreglo.length; j++)
          {
              temp+=arreglo[j];
          }
          boolean repit=false;
          for(int j=0; j<permutacion.size(); j++)
          {
              if(temp.equals(permutacion.get(j).toString()))
              {
                  repit = true;
              }

          }
          if(repit==true)
          {
              i--;
          }
          else if(repit==false)
          {

              permutacion.addElement(temp);
          }

      }
        for(int i=0; i<permutacion.size(); i++)
        {
            String temp="";
            char arr[]=permutacion.get(i).toString().toCharArray();
            for(int j=0; j<arr.length; j++)
            {
                temp+=cadena.charAt(Integer.parseInt(""+arr[j]));
             }
            permutacion.set(i, temp);
            }

    }
}
    
asked by diego reyes 03.08.2018 в 03:02
source

0 answers