Advertisement
Guest User

Matice

a guest
May 6th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.97 KB | None | 0 0
  1. package ipalpzapocet;
  2.  
  3. import java.util.Arrays;
  4.  
  5. /**
  6.  *
  7.  * @author Wanis_
  8.  */
  9. public class Matice<T> {
  10.     private Object[][] matice;
  11.  
  12.     public Matice(int m, int n) {
  13.         matice = new Object[m][n];
  14.     }
  15.    
  16.     public T vratPrvek(int m, int n){
  17.         try {
  18.             return (T) matice[m][n];
  19.         }
  20.         catch (Exception e) {
  21.             throw e;
  22.         }
  23.     }
  24.    
  25.     public void vlozPrvek(T prvek, int m, int n){
  26.         try {
  27.             matice[m][n] = prvek;
  28.         }
  29.         catch (Exception e) {
  30.             throw e;
  31.         }
  32.     }
  33.  
  34.     @Override
  35.     public String toString() {      
  36.         return Arrays.deepToString(matice);
  37.     }
  38.    
  39.     public void vypisMatici(){
  40.         for (int i = 0; i < matice.length; i++) {
  41.             for (int j = 0; j < matice[i].length; j++) {
  42.                 System.out.printf("%6d", matice[i][j]);
  43.             }
  44.             System.out.println("");
  45.         }
  46.     }
  47.    
  48.    
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement