Guest User

Untitled

a guest
Jun 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public class Test{
  2. public static void main(String[] args) {
  3. try (BufferedReader reader = new BufferedReader(new FileReader("test.txt"))) {
  4. long[] unicodeArray = new long[65536];
  5.  
  6. while (reader.ready()) {
  7. char[] charArray = reader.readLine().toCharArray();
  8. for (char c : charArray) {
  9. unicodeArray[(int) c]++;
  10. }
  11. }
  12.  
  13. for (int i = 0; i < unicodeArray.length; i++) {
  14. if (unicodeArray[i] > 0) {
  15. System.out.println("Symbol: " + (char) i + " Freq: " + unicodeArray[i]);
  16. }
  17. }
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. }
  23.  
  24. try (InputStream reader = new FileInputStream("test.txt")) {
  25. long[] unicodeArray = new long[65536];
  26. byte[] buf = new byte[4096];
  27. int len;
  28. short maxChar;
  29. long maxCharCnt = 0;
  30.  
  31. while ((len = reader.read(buf)) > 0) {
  32. for (int i = 0; i < len; i += 2) {
  33. short c = (buf[i] << 8) || (buf[i + 1] & 0xff);
  34. unicodeArray[c]++;
  35. if (unicodeArray[c] > maxCharCnt) {
  36. maxChar = c;
  37. maxCharCnt = unicodeArray[c];
  38. }
  39. }
  40.  
  41. System.out.println((char)maxChar);
  42. }
Add Comment
Please, Sign In to add comment