Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class T5p2 {
- Scanner teclado = new Scanner(System.in);
- int n,m, x, cont;
- int matriz [][];
- public void crearmatriz() {
- System.out.print("Ingrese número de columnas: ");
- n = teclado.nextInt();
- System.out.print("Ingrese número de filas: ");
- m = teclado.nextInt();
- matriz = new int [n][m];
- }
- public void proceso() {
- for (int i = 0; i < matriz.length; i++) {
- for (int j = 0; j < matriz.length; j++) {
- System.out.print("Ingrese dato posición ("+i+","+j+"): ");
- matriz [i][j] = teclado.nextInt();
- }
- }
- System.out.print("Ingrese dato a buscar: ");
- x = teclado.nextInt();
- for (int i = 0; i < matriz.length; i++) {
- for (int j = 0; j < matriz.length; j++) {
- if(matriz [i][j]== x) {
- cont++;
- }
- }
- }
- }
- public void mostrar() {
- System.out.println("El dato se repite: "+cont);
- }
- public static void main(String[] args) {
- T5p2 fc = new T5p2();
- fc.crearmatriz();
- fc.proceso();
- fc.mostrar();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment