fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args)
  11. {
  12. boolean run = true;
  13. try(Scanner scanner = new Scanner(System.in))
  14. {
  15. while (run)
  16. {
  17. System.out.println("Another action? [Y/N]");
  18. while (!scanner.hasNext("[YyNnFf]")) {
  19. System.out.println("Incorrect input");
  20. scanner.next();
  21. }
  22. String choice = scanner.next();
  23. if (choice.toLowerCase().equalsIgnoreCase("f"))
  24. run = false;
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.07s 29232KB
stdin
Y y o A N n F
stdout
Another action? [Y/N]
Another action? [Y/N]
Another action? [Y/N]
Incorrect input
Incorrect input
Another action? [Y/N]
Another action? [Y/N]