When I was turn it on IntelliJ everything works, but the task dismissed 4 subsection.
The second problem :
When i used
for(Integer k : lista){
System.out.print(lista.get(k)+" ");
}
i have somethin like that :
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 97 out of bounds for length 11
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:359)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at trzy.main(trzy.java:32)
Any suggestion ?
package pl.codegym.task.task18.task1805;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
/*
Sortowanie bajtów
*/
public class Solution {
static ArrayList<Integer> lista = new ArrayList<>();
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<Integer, Integer> mapa = new HashMap<Integer, Integer>();
String s = reader.readLine();
reader.close();
FileInputStream fileInputStream = new FileInputStream(s);
while (fileInputStream.available() > 0){
int bajt = fileInputStream.read();
mapa.put(bajt,1);
}
fileInputStream.close();
zMapnaList(mapa);
Collections.sort(lista);
/*for(Integer k : lista){
System.out.print(lista.get(k)+" ");
}*/
for(int k = 0 ; k < lista.size(); k++)
System.out.print(lista.get(k)+" ");
}
private static void zMapnaList(HashMap<Integer,Integer> mapka){
for(Map.Entry<Integer,Integer> para : mapka.entrySet()){
lista.add(para.getKey());
}
}
}