【发布时间】:2014-03-13 20:14:55
【问题描述】:
这是我的所有代码,总而言之,它标准化了两个文本文件,然后打印出结果。
import java.io.*;
import java.util.*;
public class Plagiarism {
public static void main(String[] args) {
Plagiarism myPlag = new Plagiarism();
if (args.length == 0) {
System.out.println("Error: No files input");
}
else if (args.length > 0) {
try {
for (int i = 0; i < args.length; i++) {
BufferedReader reader = new BufferedReader (new FileReader (args[i]));
List<String> foo = simplify(reader);
for (int j = 0; j < foo.size(); j++) {
System.out.print(foo.get(j));
}
}
}
catch (Exception e) {
System.err.println ("Error reading from file");
}
}
}
public static List<String> simplify(BufferedReader input) throws IOException {
String line = null;
List<String> myList = new ArrayList<String>();
while ((line = input.readLine()) != null) {
myList.add(line.replaceAll("[^a-zA-Z0-9]","").toLowerCase().trim());
}
return myList;
}
}
我要实现的下一点是:使用命令行,第三个参数将是用户输入的任何整数(块大小)。然后我必须使用它将该数组的元素存储到重叠的单独块中。 EG:猫坐在垫子上,块大小为 4。块 1 将是:Thec 块 2:heca 块 3:ecat,依此类推,直到它到达数组的末尾。
有什么想法吗?
提前谢谢各位。
【问题讨论】:
标签: java arraylist block bufferedreader filereader