Llenar
una matriz donde capture por teclado el tamaño de la misma y esta solo acepte
números pares. Los resultados por
teclado.
CÓDIGO FUENTE
package manu;
import javax.swing.JOptionPane;
/**
*
* @author Admin
*/
public class Discretas {
public static void main(String[] args) {
int
n=Integer.parseInt(JOptionPane.showInputDialog("ingrese las finas de la
matriz "));
int
m=Integer.parseInt(JOptionPane.showInputDialog("ingrese las columnas de la
matriz "));
int mat[][]= new int[n][m];
int nro;
for (int i = 0; i <
n; i++) {
for (int j = 0; j
< m; j++) {
nro=Integer.parseInt(JOptionPane.showInputDialog("ingrese un numero
"));
if (nro%2==0) {
mat[i][j]=nro;
} else {
JOptionPane.showInputDialog("ingrese otro numero diferente");
}
}
}
for (int i = 0; i <
n; i++) {
for (int j = 0; j
< m; j++) {
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
}
}
SALIDA

No hay comentarios.:
Publicar un comentario