1个回答
展开全部
封装性不用担心,java正是以其良好的封装性著称。
小可献丑了:
//没有仔细调试,按照提示输入数据
//每一行(Row)数据用空格隔开,结束后回车
import java.io.*;
import java.util.*;
public class Arrtest{
public static void main(String args[]){
try{
System.out.print("set the row of the arr:\n");
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
String row=in.readLine();
System.out.print("set the line of the arr:\n");
BufferedReader in2=new BufferedReader(
new InputStreamReader(System.in));
String line=in2.readLine();
int R=Integer.parseInt(row);
int L=Integer.parseInt(line);
Arr arr=new Arr();
System.out.print("Great the first arr:\n");
double arr1[][]=arr.greatArr(R,L);
System.out.print("Great the second arr:\n");
double arr2[][]=arr.greatArr(R,L);
arr.showArr(arr.addArr(arr1,arr2,R,L),R,L);
}catch(Exception e){e.getMessage(); }
}
}
class Arr {
double[][] greatArr(int row,int line){
double arr[][]=new double[row][line];
for(int i=0;i<row;i++){
try{
System.out.print("input the row("+(i+1)+") numbers:\n");
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
String s=in.readLine();
StringTokenizer s_part=new StringTokenizer(s," ");
for(int j=0;j<line;j++){
arr[i][j]=Double.parseDouble(s_part.nextToken());
}
}catch(Exception e){e.getMessage(); }
}
return arr;
}
double[][] addArr(double[][] arr1,double[][] arr2,int row,int line){
for(int i=0;i<row;i++){
for(int j=0;j<line;j++){
arr1[i][j]=arr1[i][j]+arr2[i][j];
}
}
return arr1;
}
void showArr(double[][] arr,int row,int line){
System.out.print("the result:\r\n");
for(int i=0;i<row;i++){
for(int j=0;j<line;j++){
System.out.print(arr[i][j]+" ");
}
System.out.print("\r\n");
}
}
}
小可献丑了:
//没有仔细调试,按照提示输入数据
//每一行(Row)数据用空格隔开,结束后回车
import java.io.*;
import java.util.*;
public class Arrtest{
public static void main(String args[]){
try{
System.out.print("set the row of the arr:\n");
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
String row=in.readLine();
System.out.print("set the line of the arr:\n");
BufferedReader in2=new BufferedReader(
new InputStreamReader(System.in));
String line=in2.readLine();
int R=Integer.parseInt(row);
int L=Integer.parseInt(line);
Arr arr=new Arr();
System.out.print("Great the first arr:\n");
double arr1[][]=arr.greatArr(R,L);
System.out.print("Great the second arr:\n");
double arr2[][]=arr.greatArr(R,L);
arr.showArr(arr.addArr(arr1,arr2,R,L),R,L);
}catch(Exception e){e.getMessage(); }
}
}
class Arr {
double[][] greatArr(int row,int line){
double arr[][]=new double[row][line];
for(int i=0;i<row;i++){
try{
System.out.print("input the row("+(i+1)+") numbers:\n");
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
String s=in.readLine();
StringTokenizer s_part=new StringTokenizer(s," ");
for(int j=0;j<line;j++){
arr[i][j]=Double.parseDouble(s_part.nextToken());
}
}catch(Exception e){e.getMessage(); }
}
return arr;
}
double[][] addArr(double[][] arr1,double[][] arr2,int row,int line){
for(int i=0;i<row;i++){
for(int j=0;j<line;j++){
arr1[i][j]=arr1[i][j]+arr2[i][j];
}
}
return arr1;
}
void showArr(double[][] arr,int row,int line){
System.out.print("the result:\r\n");
for(int i=0;i<row;i++){
for(int j=0;j<line;j++){
System.out.print(arr[i][j]+" ");
}
System.out.print("\r\n");
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |