Advertisement
cd62131

Count Numeric

Dec 13th, 2013
1,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.69 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4. import java.util.TreeMap;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Main {
  8.   public static void main(String[] args) {
  9.     Scanner in = null;
  10.     try {
  11.       in = new Scanner(new File(args[0]));
  12.     }
  13.     catch (Exception e) {
  14.     }
  15.     Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
  16.     Pattern p = Pattern.compile("\\d");
  17.     while (in.hasNext(p)) {
  18.       int i = 0;
  19.       try {
  20.         i = new Integer(in.next(p));
  21.       }
  22.       catch (Exception e) {
  23.       }
  24.       if (map.get(i) == null) map.put(i, 0);
  25.       else map.put(i, map.get(i) + 1);
  26.     }
  27.     System.out.println(map);
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement