Advertisement
Bidderlyn

2

Nov 25th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class MatrixMul here.
  4. *
  5. * @author Dov Triestman
  6.  
  7. */
  8. public class MatrixMul
  9. {
  10. int N =((int)((Math.random()*2)+2)); // 1<N<4
  11. int maxValue= ((int)((Math.random()*8)+2)); // 1<maxValue<10
  12.  
  13. int[][] m1 = new int[N][N];
  14. int[][] m2 = new int[N][N];
  15. int[][] m3 = new int[N][N];
  16.  
  17. public MatrixMul()
  18. {
  19. System.out.println("What is the N?: "+N);
  20. System.out.println("What is the maxValue?: "+maxValue);
  21. for(int i =0; i<N; i++)
  22. {
  23. for(int j=0; j<N; j++)
  24. {
  25. int random = ((int)((Math.random()*10)+1));
  26. m1[i][j] = random;
  27. m2[i][j] = random;
  28.  
  29. boolean trueRandom = false;
  30. while(trueRandom == false)
  31. {
  32. random = ((int)((Math.random()*maxValue)+1));
  33. if(random > maxValue)
  34. {
  35. trueRandom = false;
  36. }
  37. else
  38. trueRandom =true;
  39. }
  40.  
  41. System.out.println("Printing m1["+i+"],["+j+"]");
  42. System.out.println(m1[i][j]);
  43. System.out.println("Printing m2["+i+"],["+j+"]");
  44. System.out.println(m2[i][j]);
  45. System.out.println("Printing m3["+i+"],["+j+"]");
  46. for(int k=0;k<N;k++)
  47. {
  48. m3[i][j] += m1[i][k] + m2[k][j];
  49. System.out.println(m3[i][j]);
  50. }
  51.  
  52.  
  53. /*
  54. System.out.println("Printing m3");
  55. for(int k=0; k<N; k++)
  56. {
  57. m3[i][j] += m1[i][k] + m2[k][j];
  58. }
  59. */
  60. }
  61. }
  62.  
  63.  
  64. /*N = ((int)((Math.random()*4)+1));
  65. maxValue = ((int)((Math.random()*10)+1));
  66. */
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement