日期:2014-05-20 浏览次数:20741 次
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ChangeNumbersNew { static List<String> strList = new ArrayList<String>(); public static void main(String[] args) { File f = new File("out.txt"); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(f); br = new BufferedReader(fr); String lineStr = ""; String s = ""; while((lineStr = br.readLine()) != null){ lineStr = lineStr.replaceAll(" ", ""); for(int i=0;i<lineStr.length();i++){ if(isNumber(lineStr.charAt(i))){ s += String.valueOf(lineStr.charAt(i)); }else{ if(s != ""){ strList.add(s); s = ""; } } if(i == lineStr.length()-1){ strList.add(s); s = ""; } } } } catch (Exception e) { e.printStackTrace(); } finally{ try { if(br != null){ br.close(); br = null; } if(fr != null){ fr.close(); fr = null; } } catch (IOException e) { e.printStackTrace(); } } String outLine = ""; for(int i = 1;i <= strList.size();i++){ outLine += (getNumbers(strList.get(i-1)))+"、"; if(i%3 == 0){ if(outLine.endsWith("、")){ outLine = outLine.substring(0,outLine.length()-1); } System.out.println(outLine); outLine = ""; } } } static boolean isNumber(char c){ if(c >= '0' && c <= '9'){ return true; } return false; } static String getNumbers(String s){ List<String> numList = new ArrayList<String>(); for(int i = 0;i<10;i++){ numList.add(String.valueOf(i)); } for(int i = 0;i<s.length();i++){ char c = s.charAt(i); for(int j = 0;j<numList.size();j++){ if(numList.get(j).equals(String.valueOf(c))){ numList.remove(j); } } } String retVal = ""; for(String str:numList){ retVal += str; } return retVal; } }