-2

How to print the array with this value inserted? I need to show the initial array, the between array and the end array.

public class ExercicioVetores {

    /*
     * Programa que recebe valores do usuário, 
     * 1 Valor do tamanho do vetor. 
     * 2 Valor da posiçao onde será inserido um dado 
     * 3 Valor á ser inserido na posição informada
     * 4 Imprimir o vetor com o valor inserido na posição informada
     * 5 Inserir todos os valores e mostrar o vetor completo.
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Digite o TAMANHO do vetorBase que deseja criar.");

        //Inicia o método que vai buscar as informações imputadas no System.in
        Scanner teclado = new Scanner(System.in); 
        // Criando vetor com parametro recebido.
        int vetorBase[] = new int[teclado.nextInt()];
        // Iniciando vetor com valores zarados
        Arrays.fill(vetorBase, 0); 
        System.out.println("O vetorBase tem TAMANHO = " + vetorBase.length);

        //Mostrando os valores do vetor criado
        for (int i : vetorBase) {
            System.out.printf(" " + vetorBase[i]);
        }
        System.out.println("");

        System.out.println("Digite a POSIÇÃO que deseja inserir um VALOR.");
        int posicaoValor = teclado.nextInt();

        System.out.println("Digite o VALOR que deseja inserir na POSIÇÃO.");
        int valorInserido = teclado.nextInt();

        System.out.println("Será inserido no vetorBase de TAMANHO = " + vetorBase.length + ", na POSIÇÃO = "+ posicaoValor + ", o VALOR = " + valorInserido);
        vetorBase[posicaoValor] = valorInserido; //Vetor Base na posicaoValor recebe o valorInserido.

//Imprimir o vetor criado para mostrar a posição que foi inserido o valor na posição correta.
//On this point i like to print the array with the value inserted.

        for (int i : vetorBase) {
            System.out.println("");
        }
        
        
        
        
        /*
         * Arrays.sort(vetorBase); Ordenação do vetor int mostrarPosicao =
         * Arrays.binarySearch(num,1); Buscar valor
         */

    }// main

}// class
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    Does this answer your question? [What's the simplest way to print a Java array?](https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array) – Peroxy Aug 29 '20 at 13:27

1 Answers1

2

you can print the array with

System.out.println(Arrays.toString(vetorBase))

you are not printing anything with:

 for (int i : vetorBase) {
        System.out.println("");
    }