For Details of The Program: CLICK HERE
import
java.io.*;
{
int
a[][],m,i,j;
BufferedReader
br=new BufferedReader(new InputStreamReader(System.in));
void accept( )
throws Exception
{
System.out.print("\nEnter
no of rows:");
m=Integer.parseInt(br.readLine());
check();
}
void check( )
throws Exception
{
if(m<=2
||m >10)
System.out.println("Invalid
Input.");
else
{
a=new
int[m][m];
m--;
for(i=0;i<=m;i++)
{
for(j=0;j<=m;j++)
{
System.out.print("\nEnter
Value:");
a[i][j]=Integer.parseInt(br.readLine());
}
}
show();
}
}
void show()
{
System.out.println("\nThe
original matrix");
for(i=0;i<=m;i++)
{
for(j=0;j<=m;j++)
{
System.out.print("
"+a[i][j]);
}
System.out.println();
}
System.out.println("\n=nThe
matrix after rotation:");
for(i=0;i<=m;i++)
{
for(j=0;j<=m;j++)
{
}
System.out.println();
}
}
public static
void main(String args[]) throws Exception
{
Q2 one=new Q2
();
one.accept();
}
}
Variable
description
Type
|
Variable Name
|
Purpose
|
Scope
|
int
|
A[][]
|
To store the
|
Entire program
|
|
|
values
|
|
int
|
i
|
Loop control
|
Entire program
|
|
|
variable
|
|
int
|
j
|
Loop control
|
Entire program
|
|
|
variable
|
|
int
|
m
|
Size of the matrix
|
Entire program
|
Algorithm
|
|
|
|
Step 1: Create
int variables i,j and m. Declare an array a[][]
Step 2: Take
the size of the square matrix from user and store in m
Step 3: If ‘m’
is not within specified range, show appropriate message.
Step 4: Take
values in the array
Step 5: Display
the array and display rotating the array
No comments:
Post a Comment