Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package zadatak1;
  2.  
  3. import java.lang.Math;
  4.  
  5. public class Arraz {
  6.     int[][] matrix;
  7.     int redak = 5;
  8.     int pohrana[];
  9.  
  10.     public Arraz(int[][] mat) {
  11.         matrix = mat;
  12.         redak = matrix.length;
  13.     }
  14.    
  15.    
  16.     public Arraz(int num) {
  17.         redak = num;
  18.         matrix = new int[redak][];
  19.         pohrana = new int[redak];
  20.     }
  21.    
  22.  
  23.     public void create_matrix() {
  24.        
  25.         for(int i = 0; i < redak; i++) {
  26.             int stupac = (int) Math.floor(Math.random() * 20) + 1;
  27.        
  28.             pohrana[i] = stupac; // polje u kojem zapisujem broj stupaca
  29.            
  30.             matrix[i] = new int[stupac];
  31.            
  32.             for(int j = 0; j < stupac; j++) {
  33.                 matrix[i][j] = (int) Math.floor(Math.random() * 20);
  34.             }
  35.        
  36.         }
  37.     }
  38.    
  39.    
  40. public void ispis_me() {
  41.         String str="";
  42.         for(int i = 0; i < matrix.length; i++) {
  43.             for(int j = 0; j < matrix[i].length; j++) {
  44.                 str += matrix[i][j] + " ";
  45.             }
  46.             str += "\n";
  47.         }
  48.         System.out.println(str);
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement