Advertisement
LEANDRONIEVA

matriztp2

Sep 13th, 2023
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Tabla {
  4.     private static Random rndm = new Random();
  5.  
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.  
  10.         int[][] tabla = new int[7][7];
  11.         int aux;
  12.        
  13.         for (int i=0; i <7;i++) {
  14.             for (int j=0; j<7;j++) {
  15.                 if(i==j) {
  16.                     tabla[i][j] = 1;
  17.                 }else {
  18.                     aux = rndm.nextInt(99);
  19.                     while(esPar(aux)) {
  20.                         aux = rndm.nextInt(99);
  21.                     }
  22.                     tabla[i][j] = aux;
  23.                 }
  24.                 System.out.print(" ");
  25.                 System.out.print(tabla[i][j]);
  26.                 System.out.print(" ");
  27.             }
  28.             System.out.println();
  29.         }
  30.        
  31.     }
  32.  
  33.     public static boolean esPar(int num) {
  34.         if ((num%2)==0) return true;
  35.         return false;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement