I was Trying to find a way to check the user input while typing so if they typed a special character ("#") the execution will terminate immediately without pressing Enter (using Java Scanner) , I tried this code but it needs to press enter each time .I couldn't find a way to do that I'd appreciate any help.
import java.util.Scanner;
public class test{
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
while (true) {
String input =scan.next();
if (input.equals("#")) {
break;
}
System.out.println("yes");
}
}
}