日期:2014-05-20  浏览次数:20625 次

菜鸟求大侠们解答简单的javase小程序
编写一个应用程序用来实现矩阵运算的“+”,“-”,“*”运算,并且要实现输入并存储矩阵元素及行列数的数据结构。
小弟初学Java,对该知识还不甚了解,不能完成这小的练习,还望各位
大侠哥哥们,给小弟指点一二。

------解决方案--------------------
就定义个二维矩阵嘛
------解决方案--------------------
用二维数组很好写的,加油,相信你可以的啊
------解决方案--------------------
如果要储存在文件里的话,就用IO流,存在数据库的话,就用jdbc,不过我想应该没这么复杂,这个应该就是让你写一个简单的矩阵运算,定义一个二维数组然后实习就可以了。
------解决方案--------------------
矩阵直接使用二维数组就可以了
------解决方案--------------------
public static ArrayList readTxtFile(String txtFileName, String code) {
BufferedReader reader;
ArrayList list = new ArrayList();
try{
reader = new BufferedReader(new InputStreamReader(new FileInputStream(txtFileName), code));
String lineString = "";

while(true){
lineString = reader.readLine();
if(lineString == null){
break;
}
list.add(lineString);
}
reader.close();
}catch (Exception e){
LogFactory.getLog(ReadAndWriteTxtFile.class).debug("read file name: "+txtFileName+"-------"+e.getMessage());
return null;
}
return list;
}

public static void writeTxtFile(String txtFileName,String writeString) {

FileOutputStream fops;

try {
int index = txtFileName.lastIndexOf("\\");
String path = txtFileName.substring(0, index);
File file = new File(path);
if(!file.isDirectory()) {
Process p = Runtime.getRuntime().exec("cmd /c md " + path);
p.waitFor();
}

fops = new FileOutputStream(txtFileName);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fops, "GBK"));
bw.write(writeString);
bw.close();

// FileWriter fw;
// fw = new FileWriter(txtFileName);
// fw.write(writeString);
// fw.close();
}
catch (Exception ie) {
LogFactory.getLog(ReadAndWriteTxtFile.class).debug("write file name: "+txtFileName+"-------"+ie.getMessage());
return;
}
}

这两个方法你看看,不一定那么完善。你自己修修。主要是读写时候用到的数据类型。自己转换一下。