AN*N matrix having N rows and N columns containing + or * for it's cell values is passed as the input. Two strings 51
and S2 are also passed as input. The program must search for * in a straight line (either left to right or top to bottom)
and replace them with strings S1 and S2.
Input Format:
The first line will contain the value of N.
The next N lines will contain the values for N rows having
+ and *
representing the cell values of the matrix.
The last two lines will contain the value of the two strings S1 and 52 respectively.
Output Format:
N lines with the matrix cell values containing * replaced by the characters in the string values 51 and 52.
Constraints:
4 <= N <= 100
Length of S1 and 52 is from 2 to N.
Example Input/Output 1:
Input:
10
+++
+ + + +
++
+ +
+ +
++++
+ + + + + + + + + +
MANAGE
NEW
MATRIX FILL TWO WORDS PROGRAM
Answers
Answer:
Education is very necessary for each and everyone in order to improve knowledge, way of living as well as social and economic status throughout the life. ... It helps a person to get knowledge and improve confidence level all through the life. It plays a great role in our career growth as well as in the personal growth.04-Oct-2016
Answer:
import java.util.Scanner;
public class ExArrayFillWithDIffCharacters
{
public static void main(String args[])
{
// create scanner class object.
Scanner Sc = new Scanner(System.in);
// enter the size here.
System.out.print("Enter size of the Array : ");
int n = Sc.nextInt();
// enter size in given range.
if(n<2 || n>10)
System.out.print("Size out of Range");
else
{
// declare array object.
char A[][]=new char[n][n];
// enter different characters for filling the array
System.out.print("Enter first character : ");
char c1 = Sc.next().charAt(0);
System.out.print("Enter second character : ");
char c2 = Sc.next().charAt(0);
System.out.print("Enter third character : ");
char c3 = Sc.next().charAt(0);
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
// Filling the diagonals with third character
if(i==j || (i+j)==(n-1))
A[i][j] = c3;
else // Filling all other positions with second character
A[i][j] = c2;
}
}
for(int i=0; i<n/2; i++)
{
for(int j=i+1; j<n-1-i; j++)
{
// Filling the upper positions.
A[i][j] = c1;
// Filling the lower positions.
A[n-1-i][j] = c1;
}
}
// Printing the Matrix
System.out.println("\nOutput : \n");
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
System.out.print(A[i][j]+" ");
}
System.out.println();
}
}
}
}
Explanation: