There is a file report.CSV .
The program's task is to count how many times a word from column К and to calculate the sum of numbers from column R for each word from column К
Here is the program:
public class CSVtestclass { public static void main(String[] args) throws IOException { String FileName = "c:\\TestJava\\report.csv"; File file = new File(FileName); Map<String, WordInfo> wordInfoMap = new HashMap<>(); try(BufferedReader read = new BufferedReader(new FileReader(file))){ String s; String wordName; HashMap<String, int[]> stringIntegerHashMap = new HashMap<>(); read.readLine(); while( (s = read.readLine()) != null) { String[] next = s.split(";"); wordName = next[10]; if (stringIntegerHashMap.containsKey(wordName)) { int[] ints = stringIntegerHashMap.get(wordName); ints[0]++; ints[1] += Integer.parseInt(next[17]); } else { stringIntegerHashMap.put(wordName, new int[]{1, Integer.parseInt(next[17])}); } } for (Map.Entry<String, int[]> pair: stringIntegerHashMap.entrySet()) { int[] value = pair.getValue(); System.out.printf("%s zayavki: %d interakcii: %d%n", pair.getKey(), value[0], value[1]); } } catch (FileNotFoundException e) { e.printStackTrace(); } } } During program execution, an error occurs:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""0"" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:638) at java.base/java.lang.Integer.parseInt(Integer.java:770) at CSVpack.CSVtestclass.main(CSVtestclass.java:31) Where am I wrong?
