3 10 20 21 23 34 36 39 41 53 56 64 68 76 85 87 91 94 101 105 115 119
1 10 19 21 24 34 36 39 42 53 56 64 68 76 85 87 91 94 101 105 115 121
3 9 19 21 30 34 36 40 42 53 58 64 68 76 85 87 91 94 101 104 116 123
3 10 14 22 29 34 37 39 41 54 58 64 68 76 85 87 91 94 97 105 113 119
3 9 20 21 23 34 36 39 42 53 56 64 68 76 85 87 91 94 101 104 115 119
1 10 19 21 23 34 36 39 45 53 56 64 68 76 85 87 91 94 101 104 115 121
比方第一列,3的个数是5,1的个数是2,然后再第二列10的个数是5……
然后输出每个数及其个数?
try {
File file = new File("D:/work/eclipse_workspace/TST/src/l.txt");
FileReader reader = new FileReader(file);
BufferedReader in = new BufferedReader(reader);
String currentLine = "";
StringBuffer strBuffer = new StringBuffer(1000);
while ((currentLine = in.readLine()) != null) {
strBuffer.append(currentLine);
strBuffer.append("@");
}
String[] strTemp = (strBuffer.toString()).split("@");
if (strTemp.length > 0) {
int numberCount = strTemp[0].split(" ").length;
String[][] strResult = new String[strTemp.length][numberCount];
for (int i = 0; i < strTemp.length; ++i) {
strResult[i] = strTemp[i].split(" ");
}
for (int j = 0; j < numberCount; j++) {
TreeMap<String, Integer> numbersMap = new TreeMap<String, Integer>();
for (int i = 0; i < strResult.length; i++) {
if (numbersMap.containsKey(strResult[i][j])) {
int count = (Integer) numbersMap
.get(strResult[i][j]);
numbersMap.put(strResult[i][j], count + 1);
} else {
numbersMap.put(strResult[i][j], 1);
}
}
Iterator it =numbersMap.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
System.out.println(key + "的数量是:" + numbersMap.get(key));
}
System.out.println("\n");
}
in.close();
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}