Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ex_3_pl8;
- import java.util.Scanner;
- /**
- *
- * @author HP
- */
- public class EX_3_PL8 {
- static Scanner ler = new Scanner(System.in);
- public static void main(String[] args) {
- int m[][] = new int[dim()][dim()];
- elementos(m);
- mostrarMatriz(m);
- int[][] res = numerosDiferentes(m);
- mostrarMatriz(res);
- }
- public static int dim() {
- return ler.nextInt();
- }
- public static void elementos(int m[][]) {
- for (int i = 0; i < m.length; i++) {
- for (int j = 0; j < m[i].length; j++) {
- m[i][j] = ler.nextInt();
- }
- }
- }
- public static void mostrarMatriz(int m[][]) {
- String res = "";
- for (int i = 0; i < m.length; i++) {
- for (int j = 0; j < m[i].length; j++) {
- res += " " + m[i][j];
- }
- res += "\n";
- }
- System.out.println(res);
- }
- public static int[][] numerosDiferentes(int m[][]) {
- int cont = 0, cont1 = 0;
- int res[][];
- res = new int[1][cont];
- for (int i = 0; i < m.length; i++) {
- for (int j = 0; j < m[i].length; j++) {
- if (m[i][j] != res[0][cont]) {
- m[i][j] = res[0][cont];
- cont++;
- }
- }
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement