Advertisement
Guest User

matrices lab

a guest
Nov 19th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. This lab will also be on the repl.it classroom for you to complete and turn in.
  2. Problem #1
  3. Goal:
  4. This lab was designed to teach you more about processing matrices.
  5. Lab Description:
  6. Pass in a matrix and print a list that contains the total values of each row. Use the same format as the Sample Output below.
  7. Sample Data :
  8. {{1,2,3},{5,5,5,5}}
  9. {{1,2,3},{5},{1},{2,2}};
  10. {{1,2},{5,5},{5,5},{4,5,6,7},{123124,12312}};
  11.  
  12.  
  13. Sample Output :
  14. Row totals are :: [6, 20]
  15. Row totals are :: [6, 5, 1, 4]
  16. Row totals are :: [3, 10, 10, 22, 135436]
  17.  
  18. Problem #2
  19. Goal:
  20. This lab was designed to teach you more about processing matrices.
  21. Lab Description:
  22. Write a program to make a magic square of numbers. A magic square is a matrix of numbers. Every column, every row, and every diagonal add up to the same value. Read in matrix values and determine if the sum of all rows, columns, and diagonals is the same. Print out the matrix like the Sample Output. If all have the same sum, print out MAGIC SQUARE. Otherwise, print NOT A MAGIC SQUARE.
  23. Sample Input :
  24. {{8,1,6},{3,5,7},{4,9,2}}
  25. {{6,1,8},{7,5,3},{2,9,4}}
  26. {{8,3,1},{3,5,7},{9,4,2}}
  27.  
  28.  
  29. Sample Output :
  30. 8 1 6
  31. 3 5 7
  32. 4 9 2
  33. MAGIC SQUARE
  34.  
  35.  
  36. 6 1 8
  37. 7 5 3
  38. 2 9 4
  39. MAGIC SQUARE
  40.  
  41.  
  42. 8 3 1
  43. 3 5 7
  44. 9 4 2
  45. NOT A MAGIC SQUARE
  46.  
  47.  
  48.  
  49.  
  50.  
  51. //////////////////////////////////////////////////////////////////// Starting Code
  52.  
  53. class Main {
  54. public static void main(String[] args) {
  55. System.out.println("Testing Problem1");
  56. int[][] arr1 = {{1,2,3},{5,5,5,5}};
  57. int[][] arr2 = {{1,2,3},{5},{1},{2,2}};
  58. int[][] arr3 = {{1,2},{5,5},{5,5},{4,5,6,7},{123124,12312}};
  59. problem1(arr1);
  60. problem1(arr2);
  61. problem1(arr3);
  62.  
  63. System.out.println("Testing Problem2");
  64. int[][] arr4 = {{8,1,6},{3,5,7},{4,9,2}};
  65. int[][] arr5 = {{6,1,8},{7,5,3},{2,9,4}};
  66. int[][] arr6 = {{8,3,1},{3,5,7},{9,4,2}};
  67. problem2(arr4);
  68. problem2(arr5);
  69. problem2(arr6);
  70. }
  71.  
  72. /*
  73. method name: problem1
  74. method returns: nothing
  75. method parameters: 2D int Array
  76. Put the method for problem1 beneath this comment*/
  77.  
  78. /*
  79. method name: problem2
  80. method returns: nothing
  81. method parameters: 2D int Array
  82. Put the method for problem2 beneath this comment*/
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement