Page 481 - computer science (868) class 11
P. 481
The output of the preceding program is as follows:
enter the size of the matrix
3
enter array elements
1
2
3
4
5
6
7
8
9
ORIGINAL MATRIX
1 2 3
4 5 6
7 8 9
MIRROR MATRIX
3 2 1
6 5 4
9 8 7
Variable Description
NAME TYPE DESCRIPTION
a int To store the array
i int Loop variable
j int Loop variable
b int To store the mirror matrix
Program 16 Define a class Spiral_Matrix to input and print the spiral of a user-defined matrix (2-D array).
The data members and member methods are defined as follows:
Data Members
int A[][] : to store the array
int n : to store the size of the array
Member Methods
void input() : to input the size of the array
void spiral() : to find the spiral matrix and print it
Write the main method to call the methods and print the spiral of the matrix.
1 import java.util.*;
2 class Spiral_Matrix
3 {
4 int n;
5
6 void spiralprint(){
479
Internal Assessment 479

