[Java]
/*
* Start the program header annotation.
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: Create a matrix class
* Author: Xue Guangchen
* Completion date: January 1, September 27, 2011
* Version No.: x1.0
* Description of tasks and Solutions
* Input description:
* Problem description: encapsulate a class of matrix objects that can initialize the matrix and modify matrix elements.
* Program output:
* End the comment in the program Header
*/
Package xue;
Public class MatrixPlus {
/**
* @ Param args
*/
Int [] [] M;
Int column;
Int row;
MatrixPlus (){
This. column = 5;
This. row = 5;
M = new int [column] [row];
For (int I = 0; I <column; I ++)
{
For (int j = 0; j <M [I]. length; j ++)
{
M [I] [j] = 1;
}
}
}
MatrixPlus (int column, int row ){
This. column = column;
This. row = row;
M = new int [column] [row];
For (int I = 0; I <column; I ++)
{
For (int j = 0; j <M [I]. length; j ++)
{
M [I] [j] = 1;
}
}
}
Public void set_Column (int column ){
This. column = column;
M = new int [column] [row];
For (int I = 0; I <column; I ++)
{
For (int j = 0; j <M [I]. length; j ++)
{
M [I] [j] = 1;
}
}
}
Public void set_Row (int row ){
This. row = row;
M = new int [column] [row];
For (int I = 0; I <column; I ++)
{
For (int j = 0; j <M [I]. length; j ++)
{
M [I] [j] = 1;
}
}
}
Public void change_Plus (int column, int row, int)
{
M [column] [row] =;
}
Public void display (){
System. out. println ("this is an action:" + column + "column:" + row + "matrix ");
For (int I = 0; I <column; I ++)
{
For (int j = 0; j <M [I]. length; j ++)
{
System. out. print (M [I] [j] + "");
}
System. out. println ();
}
}
}
// Test class
Package xue;
Public class TestMatrixPlus {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
MatrixPlus M = new MatrixPlus ();
M. display ();
M. set_Column (6 );
M. set_Row (6 );
M. change_Plus (3, 4, 5 );
M. display ();
}
}
Running result: