my code is never closing my Scanner input stream. It let's me type in stuff in the console but does not close it with enter.
public Stack<String> einlesen(){
Scanner sc = new Scanner(System.in);
Stack<String> st = new Stack<>();
//String zeichen;
System.out.println("Bitte geben Sie einen Text ein: ");
while (sc.hasNext()) {
st.push(sc.next());
}
//sc.close();
return st;
}
Edit:
How can I achieve, that I can type text in the console and when I hit the Enter key, it jumps back from console to my code? Like the readline() function.
Edit2:
Ok since it doesn't seem to be possible that easy with the scanner class. I will try it with the DataInputStream Class. I will try something like: first write some text in console, write that whole thing into a variable and then go through every single character in that variable. Thanks for your help though.