Write a program in Java to allow the user to create a square matrix M[][] of order ‘N’.
The maximum value possible for ‘N’ is 10 >= N > 3.
Accept three different characters from the keyboard and fill the array according to the instructions given below:
- Fill the upper and lower elements formed by the intersection of the diagonals by character 1.
- Fill the left and right elements formed by the intersection of the diagonals by character 2.
- Fill both the diagonals by character 3.
Show the output in the format given below:
Example:
INPUT:
Enter size: 4
First character: *
Second character: ?
Third character: #
OUTPUT:
# * * # ? # # ? ? # # ? # * * #
import java.io.*; class FillMatrix{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Square matrix size: "); int n = Integer.parseInt(br.readLine()); if(n > 10 || n < 3){ System.out.println("Size out of range!"); return; } char m[][] = new char[n][n]; System.out.print("Enter first character: "); char ch1 = br.readLine().charAt(0); System.out.print("Enter second character: "); char ch2 = br.readLine().charAt(0); System.out.print("Enter third character: "); char ch3 = br.readLine().charAt(0); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(i + j <= n / 2 + 1){ m[i][j] = ch2; m[j][i] = ch1; } else if(i + j >= n){ m[i][j] = ch1; m[j][i] = ch2; } } } for(int i = 0, j = n - 1; i < n; i++, j--){ m[i][i] = ch3; m[i][j] = ch3; } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ System.out.print(m[i][j] + "\t"); } System.out.println(); } } },how to draw the logic circuit and the 4-variable K-map of the above question ?
Visit this website to find out the solutions for K-Map Problems.