Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int checkRowForSameness(int[][] matrix, int i) {
- int testValue = matrix[i][0];
- // If all values in row i are the same, then return that value.
- // Otherwise, return -1.
- for (int j = 1; j < matrix[i].length; j++) {
- if (testValue != matrix[i][j]) {
- return -1;
- }
- }
- return matrix[i][0];
- }
- public static void rowChecks(int[][] matrix) {
- // Check which rows have all of the same entries.
- // Display a message for each such row.
- // Display a different message if none of the rows
- // have all the same entries.
- // Precondition: none of the entries are -1.
- for (int i = 0; i < matrix.length; i++) {
- //Call checkRowForSameness
- int rowSame = checkRowForSameness(matrix, i);
- if (rowSame == -1) {
- System.out.println("Not same numbers on row " + i);
- }
- else if (rowSame == 1) {
- System.out.println("All 1s on row " + i);
- }
- else {
- System.out.println("All 0s on row " + i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement