Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java, write a program that prompts the user to enter a length of a square mat

ID: 674553 • Letter: I

Question

In Java, write a program that prompts the user to enter a length of a square matrix, randomly fills in 0s and 1s into the matrix, prints the matrix, and finds the rows, columns, and diagonals with all 0s or 1s.

/////////////////////////////////////////////////////////////////////////////////////////////

Here is the template for the java file that was provided:

import java.util.*;

public class ExploreMatrix
{
   public static void main(String[] args)
   {
       System.out.print("Enter the size of the matrix: ");
       Scanner scanner = new Scanner(System.in);
       int n = scanner.nextInt();
       scanner.close();
       int[][] matrix = randomZeroOneMatrix(n);
       printTwoDArray(matrix);
       rowChecks(matrix);  
       columnChecks(matrix);
       checkMajorDiagonal(matrix);
       checkSubDiagonal(matrix);
   }
  
   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.
   {
       System.out.println("rowChecks stub");
   }
  
   public static void columnChecks(int[][] matrix)
       // Check which columns have all of the same entries.
       // Display a message for each such column.
       // Display a different message if none of the columns
       // have all the same entries.
       // Precondition: none of the entries are -1.
   {
       System.out.println("columnChecks stub");
   }
  
   public static void printTwoDArray(int[][] array)
       // Display the array values.
   {
       System.out.println("printTwoDArray stub");
   }
  
   public static int[][] randomZeroOneMatrix(int n)
       // Generate an nxn matrix randomly filled
       // with zeroes and ones.
   {
       return new int[n][n]; // stub
   }
  
   public static int checkRowForSameness(int[][] matrix, int i)
       // If all values in row i are the same, then return that value.
       // Otherwise, return -1.
   {
       return -1; // stub
   }
  
   public static int checkColumnForSameness(int[][] matrix, int j)
       // If all values in col j are the same, then return that value.
       // Otherwise, return -1.
   {
       return -1; // stub
   }
  
   public static void checkMajorDiagonal(int[][] matrix)
       // Check whether all values along the major diagonal
       // of the matrix are the same.
       // Print a message accordingly.
   {
       System.out.println("checkMajorDiagonal stub");
   }
  
   public static void checkSubDiagonal(int[][] matrix)
       // Check whether all values along the sub-diagonal
       // of the matrix are the same.
       // Print a message accordingly.
   {
       System.out.println("checkMajorDiagonal stub");
   }
}

Explanation / Answer

Output:

Enter the size for the matrix: 4
1000
0111
0101
0100
No same numbers on a column
No same numbers on a row
No same numbers on the major diagonal
No same numbers on the sub-diagonal

import java.util.Scanner;
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote