Arrays enter elements in an already defined array

0

Hello forum: D I have a question: is there any way to enter elements in any position of an array?

This code allows me to duplicate the parts I want, but I want the duplicate to be able to put it in the desired part of the character array

    System.out.println("Ingrese los parámetros : ");
        a = scan.nextInt();
        b = scan.nextInt();
        String resultado="";
        char[] aCaracteres = adn.toCharArray();
        for (i = 0; i < aCaracteres.length; i++)
            System.out.print(aCaracteres[i]);
        for (; a < aCaracteres.length && a <= b; a++) {
            System.out.print(aCaracteres[a]);
        }
    }
}
    
asked by Teren 25.06.2018 в 02:22
source

1 answer

0

I attach my code:

   // Datos de ejemplo
   String ejemplo ="perro";
   String palabra="gato";
   int posicion=3;
    // Vamos a insertar "gato" apartir de la 3 letra de perro
   String resultado="";
   char[] array = ejemplo.toCharArray();
    for (int i =0;i<array.length;i++){
        resultado += array[i];
        // Filtro por las posicion que me mandan
        if (i==posicion){
            for (int j =0;j<palabra.length();j++){
                resultado += palabra.charAt(j);
            }
        }
    }
    System.out.println(resultado);
    
answered by 25.06.2018 / 03:35
source