修改后如下package demo1;
import java.io.*;class array_temp
{
int[][] _data = null;
public array_temp(int[][] data){
this._data = data;//构造函数,传递数组
} public String getFormatStr(){
if (_data==null||_data.length==0||this._data[0].length==0){
return null;//如果数组为空
}
int rowCount= this._data.length;//获取行数
int colCount= this._data[0].length;//获取列数
//定义返回字符串
String output = "The Data of two dimensional array:\n";
for (int i=0;i<rowCount ;i++ ){ //输出原始二维数组
for (int j=0;j<colCount ;j++ ){
if ( j == 0 && i == 0 ) output += "┏";
if ( j == 0 && i == rowCount-1 ) output += "┗";
if ( j == 0 && i != 0 && i != rowCount-1) output += "┃";
//二维数组的输出
output += " "+_data[i][j]+" "; if ( j == colCount-1 && i != 0 && i != rowCount-1) output += "┃";
if ( j == colCount-1 && i == 0 ) output += "┓";
if ( j == colCount-1 && i == rowCount-1 ) output += "┛";
}
output += "\n";
}
return output;
} public static void main(String[] args)
{
//预设 5 * 4 的矩阵数据
int[][] Data =
{ {9, 7, 6, 6},
{9, 7, 6, 6},
{3, 5, 3, 3},
{6, 6, 4, 7},
{7, 5, 1, 4},
{1, 2, 8, 0}
}; array_temp temp = new array_temp(Data);
System.out.println(temp.getFormatStr());
}
}调用方法见main函数
import java.io.*;class array_temp
{
int[][] _data = null;
public array_temp(int[][] data){
this._data = data;//构造函数,传递数组
} public String getFormatStr(){
if (_data==null||_data.length==0||this._data[0].length==0){
return null;//如果数组为空
}
int rowCount= this._data.length;//获取行数
int colCount= this._data[0].length;//获取列数
//定义返回字符串
String output = "The Data of two dimensional array:\n";
for (int i=0;i<rowCount ;i++ ){ //输出原始二维数组
for (int j=0;j<colCount ;j++ ){
if ( j == 0 && i == 0 ) output += "┏";
if ( j == 0 && i == rowCount-1 ) output += "┗";
if ( j == 0 && i != 0 && i != rowCount-1) output += "┃";
//二维数组的输出
output += " "+_data[i][j]+" "; if ( j == colCount-1 && i != 0 && i != rowCount-1) output += "┃";
if ( j == colCount-1 && i == 0 ) output += "┓";
if ( j == colCount-1 && i == rowCount-1 ) output += "┛";
}
output += "\n";
}
return output;
} public static void main(String[] args)
{
//预设 5 * 4 的矩阵数据
int[][] Data =
{ {9, 7, 6, 6},
{9, 7, 6, 6},
{3, 5, 3, 3},
{6, 6, 4, 7},
{7, 5, 1, 4},
{1, 2, 8, 0}
}; array_temp temp = new array_temp(Data);
System.out.println(temp.getFormatStr());
}
}调用方法见main函数
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货