Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*Llenar una matriz A[ ][ ] de enteros de tamaño n x m, donde n y m
- * son ingresados por el usuario con números desde n x m al 1,
- * hasta completar todas las posiciones de A[ ][ ]. La matriz se recorre
- * de derecha a izquierda y de arriba a abajo.*/
- public class DerechaIzquierda {
- public static void main(String[] args) {
- Scanner teclado = new Scanner(System.in);
- int n,m,x;
- int matriz [][];
- //Tamaño del array
- System.out.print("Ingrese cantidad filas: ");
- n = teclado.nextInt();
- System.out.print("Ingrese cantidad columnas: ");
- m = teclado.nextInt();
- matriz = new int [n][m];
- //llenar array
- x = n*m;
- for (int i = 0; i < matriz.length; i++) {
- for (int j = matriz[0].length -1; j >= 0; j--) {
- matriz [i][j] = x;
- x--;
- }
- }
- //Mostrar matriz
- for (int i = 0; i < matriz.length; i++) {
- for (int j = 0; j < matriz[0].length; j++) {
- System.out.print(matriz [i][j]+" ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment