Как и у многих - работает, но не проходит валидацию.
package com.javarush.task.task18.task1823;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String exit = "exit";
String name, tmp;
while (!(tmp = scanner.nextLine()).equals(exit)) {
name = tmp;
new ReadThread(name).start();
}
scanner.close();
}
public static class ReadThread extends Thread {
public ReadThread(String fileName) {
super(fileName);
//implement constructor body
}
// implement file reading here - реализуйте чтение из файла тут
@Override
public void run() {
byte[] bytes = new byte[256];
try (
FileInputStream inputStream = new FileInputStream(Thread.currentThread().getName()) ) {
while (inputStream.available() > 0)
bytes[inputStream.read()]++;
} catch (IOException e) {
e.printStackTrace();
}
int max = Integer.MIN_VALUE, maxI = 0;
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] > max) {
max = bytes[i];
maxI = i;
}
}
resultMap.put(Thread.currentThread().getName(), maxI);
}
}
}