0
    int [][] valores = new int[3][3];
        
    System.out.print ("Ingrese un valor en la posici�n [0][0]: ");
     valores[0][0] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [0][1]: ");
     valores[0][1] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [0][2]: ");
    valores[0][2] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [1][0]: ");
     valores[1][0] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [1][1]: ");
     valores[1][1] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [1][2]: ");
    valores[1][2] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [2][0]: ");
     valores[2][0] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [2][1]: ");
     valores[2][1] = lector.nextInt();
     
     System.out.print ("Ingrese un valor en la posici�n [2][2]: ");
    valores[2][2] = lector.nextInt();
            
    System.out.println ("----------------------------------------------------");
    
    for(int i = 0; i < valores.length; i++){
        for(int j = 0; j < valores[0].length; j++){
            System.out.print (valores[i][j] + "\t");
        }
        System.out.println ("");

Necesito realizar un programa que tenga una matriz de valores enteros de 3x3. Mediante el uso de ciclo for regulares necesito solicitarle al usuario que ingrese valores a la matriz indicando el indice en el cual va a insertar el valor. Una vez cargados los datos, se utiliza ciclos for-each para imprimir la matriz. Ejemplo.

[3][4][5]
[6][7][8]
[9][9][9] ```

1 respuesta 1

0

Para pedir los valores.

for (int i = 0; i < valores.length; i++) {

    for (int j = 0; j < valores[i].length; j++) {

        System.out.print("Ingrese un valor en la posición [" + i + "][" + j + "]: ");
        valores[i][j] = lector.nextInt();
    }


}
1
  • Excelente muchas gracias. el 30 oct. 2020 a las 2:15

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.