Java machine fifth week Task 5 encapsulates a matrix class

Source: Internet
Author: User

[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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.