Hilfe bei Vorstellungsgesprächen
Vorbereitung auf Vorstellungsgespräche
Lebenslauf
Jobsuche
Ressourcen
Abonnement
DE
Telegram
Anmelden
Menü öffnen
Hilfe bei Vorstellungsgesprächen
KI-Assistent
Browser-Erweiterung
Ressourcen
Herunterladen
FAQ / Hilfe
Vorbereitung auf Vorstellungsgespräche
Fragenbank
Interviewbank
Scheininterviews
Mentoren
Ressourcen
FAQ / Hilfe
Jobsuche
Automatisierung der Jobsuche
Marktanalyse
Stellenangebote
Ressourcen
Blog
FAQ / Dokumentation
Telegram Blog
Telegram Unterstützung
Legal
Rückerstattung
Bedingungen
Privatsphäre
Rechteinhaber
Zurück zu den Fragen
Fragenbank
Java - Entwickler
Frage
Senior
import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class badCounter { public static Map<String, Integer> mapOfBadNames = new HashMap<>(); protected void doProcessing(String filePath) throws IOException { try { FileInputStream fis = new FileInputStream(filePath); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); while((br.readLine())!=null){ processWords(br.readLine()); } br.close(); fis.close(); } catch (IOException | NullPointerException ex) { System.out.println(ex.getMessage()); } } private void processWords(String line) { Arrays.stream(line.split(" ")) .map(String::trim) .forEach(word -> { if(mapOfBadNames.containsKey(word)){ mapOfBadNames.put(word, mapOfBadNames.get(word)+1); } else{ mapOfBadNames.put(word, 1); } }); } public void writeResultToFile(String path) throws IOException { try { PrintWriter out = new PrintWriter(path); out.println("word,frequency"); for(Map.Entry<String, Integer> entry : mapOfBadNames.entrySet()){ out.println(entry.getKey() + "," + entry.getValue()); } out.close(); } catch (NullPointerException | IOException ex) { throw new RuntimeException("Error writing to file", ex); } } public boolean isEverythingFine() { return true; } public static void main(String[] args) { badCounter bcn = new badCounter(); try { bcn.doProcessing("bad_input.txt"); bcn.writeResultToFile("result.csv"); bcn.doProcessing("bad_input1.txt"); bcn.writeResultToFile("result1.csv"); } catch (IOException ex) { System.out.println("Something went wrong"); } } }
Als abgeschlossen markieren
Zurück
Als nächstes