Advertisement
Kochabitacja

Untitled

Oct 20th, 2016
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. Enter your code herepublic class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         Matrix obj;
  5.         obj.eye(5);
  6.         obj.print();
  7.     }
  8. }
  9.  
  10.  
  11.  
  12. ________________________________
  13.  
  14.  
  15. /**
  16.  * Created by yevvy on 14/10/2016.
  17.  */
  18. public class Matrix {
  19.  
  20.     private int row;
  21.     private int col;
  22.     private double[][] matrix;
  23.  
  24.     public Matrix(int row, int col){
  25.         matrix = new double[row][col];
  26.     }
  27.  
  28.     public void eye(int size){
  29.         matrix = new double[size][size];
  30.         row = size;
  31.         col = size;
  32.         for(int i=0; i<size; i++)
  33.             matrix[i][i]=1;
  34.     }
  35.  
  36.     public void print(){
  37.         for(int i=0; i<row; i++) {
  38.             for (int j = 0; i < col; i++)
  39.                 System.out.print(matrix[i][j]);
  40.             System.out.println();
  41.         }
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement