public class Solution {
public static void main(String[] args) throws IOException {
FileInputStream file1InputStream = new FileInputStream(args[0]);
byte[] count = new byte[128];
while (file1InputStream.available() > 0) {
int a = file1InputStream.read();
count[a]++;
}
for (int i = 0; i < count.length; i++) {
if (count[i] > 0) {
System.out.println((char) i + " " + count[i]);
}
}
file1InputStream.close();
}
package com.javarush.task.task18.task1821;
/*
Встречаемость символов
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static void main(String[] args) throws IOException {
FileInputStream file1InputStream = new FileInputStream(args[0]);
byte[] count = new byte[128];
while (file1InputStream.available() > 0) {
int a = file1InputStream.read();
count[a]++;
}
for (int i = 0; i < count.length; i++) {
if (count[i]>0){
System.out.println((char)i + " " + count[i]);
}
}
file1InputStream.close();
}
/*
Map<Integer, Integer> byteIntegerMap = new MyMap();
while (file1InputStream.available() > 0) {
byteIntegerMap.put(file1InputStream.read(), 0);
}
file1InputStream.close();
Collections.min(byteIntegerMap.values());
for (Integer bytes : byteIntegerMap.keySet()) {
if (min == byteIntegerMap.get(bytes)) {
System.out.print(bytes + " ");
}
}
static class MyMap<K, V> extends HashMap {
@Override
public Object put(Object key, Object value) {
if (value instanceof Integer) {
if (containsKey(key)) {
Integer v = (Integer) get(key) + 1;
return super.put(key, v);
} else {
// if there isn't key, value = 1
return super.put(key, 1);
}
}
return super.put(key, value);
}
}
*/
}