Advertisement
Marin126

Ex01Ej03

Dec 3rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. package com.mycompany.examen;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. *
  7. * @author anton
  8. */
  9. public class Ejercicio03 {
  10.  
  11. public static void main(String[] args) {
  12. Scanner sc = new Scanner(System.in);
  13.  
  14.  
  15. System.out.println("Introduzca un nΓΊmero");
  16. int n = Integer.parseInt(sc.nextLine());
  17.  
  18. char[][] matriz = new char[n][n];
  19.  
  20. for (int i = 0; i < n; i++) {
  21. for (int j = 0; j < n; j++) {
  22. if (i==j) {
  23. matriz[i][j] ='A';
  24. imprimeMatriz(matriz,i,j);
  25. }else{
  26. matriz[i][j]='*';
  27. imprimeMatriz(matriz,i,j);
  28. }
  29.  
  30.  
  31. }
  32. System.out.println("");
  33.  
  34. }
  35.  
  36.  
  37. }
  38.  
  39. public static void imprimeMatriz(char[][] matriz, int i, int j){
  40. System.out.print(" " + matriz [i][j]);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement