java – chatbot: not be able to apply to keep code take the input until i want it to terminate

It would be something like this: public static main(String[] args) { System.out.println(“Welcome to the CHATBOTn”); Scanner sc = new Scanner(; String g = “”; while (g.isEmpty()) { System.out.print(“> “); String g = sc.nextLine(); processInput(g); g = “”; // empty g so to keep looping; } } private void processInput(String g) { String s = g.toUpperCase(); … Read more

java – Terminate a Stream when there is no incoming Data after a certain Timeout

EDIT: My original answer (below) operated at the readLine() level, but on second thoughts it can be nicer to operate on the Stream level. Here is an approach that operates on Streams. The core function is takeUntilTime(Stream<T> stream, Instant end), and the rest are small helpers. The idea is to traverse the original stream using … Read more