---restore content starts---
Today is May 4, 2016, today is the 5th day of Learning Java Learning! Today's main learning task is to learn about two-dimensional arrays.
P96 3.7.52-dimensional array
Dynamic initialization
Data type array name [][]=new data type [number of rows] [number of columns];
For example, int a[][]=new int[7][8];
Static initialization
Data type array name [][]=new data type [][]{
{value, value, ...},{value, value, ...},...};
For example, int a[][]=new int[][]{
{1,2,3},{54,6},{8,9,10,16}};
For array data[][],
Data.length Number of rows
Data[i].length Number of columns (that is, the number of columns in the I row)
In Java, each row can have a different number of columns (jagged array)
Today, the teacher asked us to make up a program, enter the length and width, output a rectangular area and perimeter.
First paragraph of code:
Package Com.cqvie.wuyuesi;
public class Juxing {
private int length;
private int wide;
Public juxing () {}
Public juxing (int length,int wide) {
SetLength (length);
Setwide (wide);
}
public void setLength (int length) {
if (length>0) this.length=length;
}
public void Setwide (int wide) {
if (wide>0) this.wide=wide;
}
Public String Getlnfo () {
Return "perimeter perimeter is" +2* (length+wide) + ", area areas are" +length*wide;
}
}
The second piece of code
Package Com.cqvie.wuyuesi;
public class Juxingtest {
public static void Main (string[] args) {
Juxing per;
Per=new juxing (5,6);
Juxing Per2;
Per2=new juxing (7,8);
System.out.println (Per.getlnfo ());
System.out.println (Per2.getlnfo ());
}
}
Output Result:
The perimeter perimeter is 22, and the area is 30.
The perimeter perimeter is 30, and the area is 56.
---restore content ends---
5th Day of Java Learning