/* 编写一个 Java 程序,完成以下功能:
(1)声明一个名为 s 的 String 对象,并使它的内容是“My name is Carrol”;
(2)打印整个字符串;
(3)打印字符串的长度;
(4)打印字符串的第一个字符;
(5)打印最后一个字符;
(6)打印字符串的第一个单词。
2.声明一个矩阵类 Matrix,成员变量是一个二维数组,设数组元素类型为 int,请设计方法:
(1)构造方法:
Matrix() //构造一个 10X10 个元素的矩阵,没有数据
Matrix(int n,int m) //构造一个 nXm 个元素的矩阵,数据由随机数产生
Matrix(int table[][]) //以一个整型的二维数组构造一个矩阵
要求使用 this
(2) 实例方法:
public void output() //输出 Matrix 类中数组的元素值
public void transpose() //输出一个矩阵的转置矩阵
2.随机数求法:
Math.random( )返回 0-1 的小数,由上题中的 Matrix 类派生出正方形 Square 类,在构造方法
中调用父类的构造方法(使用 super)。
*/
class Matrix
{ int a[][];
Matrix()
{ a=new int[10][10];
}
Matrix(int n,int m)
{ a=new int[n][m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
a[i][j]=(int)(Math.random()*100);
}
Matrix(int table[][])
{
a=table;
}
public void output()
{ for(int i=0;i<=a.length;i++)
for(int j=0;j<=a.length;j++)
try{
System.out.print(a[i][j]+" ");
}catch (Exception e) {
return;
}
}