diloentutospc

Tamaño Matriz

Oct 15th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class T5p2 {
  4.    
  5.     Scanner teclado = new Scanner(System.in);
  6.    
  7.     int n,m, x, cont;
  8.     int matriz [][];
  9.    
  10.     public void crearmatriz() {
  11.         System.out.print("Ingrese número de columnas: ");
  12.         n = teclado.nextInt();
  13.         System.out.print("Ingrese número de filas: ");
  14.         m = teclado.nextInt();
  15.         matriz = new int [n][m];
  16.     }
  17.    
  18.     public void proceso() {
  19.         for (int i = 0; i < matriz.length; i++) {
  20.             for (int j = 0; j < matriz.length; j++) {
  21.                 System.out.print("Ingrese dato posición ("+i+","+j+"): ");
  22.                 matriz [i][j] = teclado.nextInt();
  23.             }
  24.         }
  25.         System.out.print("Ingrese dato a buscar: ");
  26.         x = teclado.nextInt();
  27.        
  28.         for (int i = 0; i < matriz.length; i++) {
  29.             for (int j = 0; j < matriz.length; j++) {
  30.                 if(matriz [i][j]== x) {
  31.                     cont++;                
  32.                 }
  33.             }
  34.         }
  35.     }
  36.    
  37.     public void mostrar() {
  38.         System.out.println("El dato se repite: "+cont);
  39.     }  
  40.  
  41.     public static void main(String[] args) {
  42.         T5p2 fc = new T5p2();
  43.         fc.crearmatriz();
  44.         fc.proceso();
  45.         fc.mostrar();
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment