Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This lab will also be on the repl.it classroom for you to complete and turn in.
- Problem #1
- Goal:
- This lab was designed to teach you more about processing matrices.
- Lab Description:
- 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.
- Sample Data :
- {{1,2,3},{5,5,5,5}}
- {{1,2,3},{5},{1},{2,2}};
- {{1,2},{5,5},{5,5},{4,5,6,7},{123124,12312}};
- Sample Output :
- Row totals are :: [6, 20]
- Row totals are :: [6, 5, 1, 4]
- Row totals are :: [3, 10, 10, 22, 135436]
- Problem #2
- Goal:
- This lab was designed to teach you more about processing matrices.
- Lab Description:
- 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.
- Sample Input :
- {{8,1,6},{3,5,7},{4,9,2}}
- {{6,1,8},{7,5,3},{2,9,4}}
- {{8,3,1},{3,5,7},{9,4,2}}
- Sample Output :
- 8 1 6
- 3 5 7
- 4 9 2
- MAGIC SQUARE
- 6 1 8
- 7 5 3
- 2 9 4
- MAGIC SQUARE
- 8 3 1
- 3 5 7
- 9 4 2
- NOT A MAGIC SQUARE
- //////////////////////////////////////////////////////////////////// Starting Code
- class Main {
- public static void main(String[] args) {
- System.out.println("Testing Problem1");
- int[][] arr1 = {{1,2,3},{5,5,5,5}};
- int[][] arr2 = {{1,2,3},{5},{1},{2,2}};
- int[][] arr3 = {{1,2},{5,5},{5,5},{4,5,6,7},{123124,12312}};
- problem1(arr1);
- problem1(arr2);
- problem1(arr3);
- System.out.println("Testing Problem2");
- int[][] arr4 = {{8,1,6},{3,5,7},{4,9,2}};
- int[][] arr5 = {{6,1,8},{7,5,3},{2,9,4}};
- int[][] arr6 = {{8,3,1},{3,5,7},{9,4,2}};
- problem2(arr4);
- problem2(arr5);
- problem2(arr6);
- }
- /*
- method name: problem1
- method returns: nothing
- method parameters: 2D int Array
- Put the method for problem1 beneath this comment*/
- /*
- method name: problem2
- method returns: nothing
- method parameters: 2D int Array
- Put the method for problem2 beneath this comment*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement