Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package ex_3_pl8;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. *
  7. * @author HP
  8. */
  9. public class EX_3_PL8 {
  10.  
  11. static Scanner ler = new Scanner(System.in);
  12.  
  13. public static void main(String[] args) {
  14. int m[][] = new int[dim()][dim()];
  15. elementos(m);
  16. mostrarMatriz(m);
  17. int[][] res = numerosDiferentes(m);
  18. mostrarMatriz(res);
  19. }
  20.  
  21. public static int dim() {
  22. return ler.nextInt();
  23. }
  24.  
  25. public static void elementos(int m[][]) {
  26. for (int i = 0; i < m.length; i++) {
  27. for (int j = 0; j < m[i].length; j++) {
  28. m[i][j] = ler.nextInt();
  29. }
  30. }
  31. }
  32.  
  33. public static void mostrarMatriz(int m[][]) {
  34. String res = "";
  35. for (int i = 0; i < m.length; i++) {
  36. for (int j = 0; j < m[i].length; j++) {
  37. res += " " + m[i][j];
  38. }
  39. res += "\n";
  40. }
  41. System.out.println(res);
  42. }
  43.  
  44. public static int[][] numerosDiferentes(int m[][]) {
  45. int cont = 0, cont1 = 0;
  46. int res[][];
  47. res = new int[1][cont];
  48. for (int i = 0; i < m.length; i++) {
  49. for (int j = 0; j < m[i].length; j++) {
  50. if (m[i][j] != res[0][cont]) {
  51. m[i][j] = res[0][cont];
  52. cont++;
  53. }
  54. }
  55. }
  56. return res;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement