fork(1) download
  1. class Go extends Exception {
  2. final int line;
  3.  
  4. Go(int line) { this.line = line; }
  5.  
  6. static void to(int line) throws Go { throw new Go(line); }
  7. }
  8.  
  9. abstract class GoToProc {
  10. int line = 0;
  11.  
  12. final void run() {
  13. while (true) {
  14. try {
  15. proc(line);
  16. return;
  17. } catch (Go goTo) {
  18. this.line = goTo.line;
  19. }
  20. }
  21. }
  22.  
  23. abstract void proc(int line) throws Go;
  24. }
  25.  
  26. public class Main {
  27. public static void main(String[] args) {
  28. GoToProc factorial = new GoToProc() {
  29. int f = 1;
  30. int x = 10;
  31.  
  32. @Override
  33. void proc(int line) throws Go {
  34. switch (line) {
  35. case 0: if (x == 0) Go.to(4);
  36. case 1: f = f * x;
  37. case 2: x = x - 1;
  38. case 3: Go.to(0);
  39. case 4: System.out.println(f);
  40. }
  41. }
  42. };
  43. factorial.run();
  44. }
  45. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
3628800