Java problem for a user to enter a char array

0

I came to ask how can I insert the values of an array in that part?

char cadena[] = {a,a,a,b,a,a,a,a,0, 1}; 

Either to scan it in the console, or to use it in jframe , but that is exactly as stated in the code.

/**
 * @param args
 */
public static void main(String[] args) {
    char a = 2;
    char b = 3;

    char cadena[] = {a,a,a,b,a,a,a,a,0, 1};

    System.out.println("Tu cadena ingresada fue: ");
    for (int i = 0; i < cadena.length; i++) {
        System.out.print(cadena[i] + ",");
    }

    int inicio = 0;
    int aceptacion = 4;
    int estado = inicio;
    boolean fin = false;
    int contador = 0;
    System.out.println("\n\nEmpezamos con contador " + contador);
    while (fin == false) {
        if (contador > cadena.length - 1) {
            System.out.println("\n\nTerminamos en el estado: " + estado
                    + "\nCon un numero de transiciones: " + contador
                    + "\nEstado de aceptacion: " + aceptacion
                    + "\nEstado inicial: " + inicio
                    + "\nCon el largo de cadena: " + cadena.length);
            fin = true;
            break;
        }


    if (estado == aceptacion) {
        System.out.println("\n\n\nLa cadena si pertence a la expresion regular");
    } else {

        System.out.println("La cadena no pertenece a la expresion regular");
    }

    }
}
    
asked by Shineruze 03.12.2017 в 06:35
source

1 answer

0

You can use this code to request the values graphically and then the result that is a String you can use a Split to separate the content properly and convert them into an array.

String texto = JOptionPane.showInputDialog(new JFrame(), "Ingrese los valores?");

now you separate it:

String cadena[] = texto.split(","); //aqui uso el separador
    
answered by 03.12.2017 в 16:35