fork download
  1. import java.io.IOException;
  2.  
  3. /**
  4.  * Example 91 - Multiple Threads
  5.  */
  6.  
  7. class Incrementer extends Thread {
  8. public int i;
  9. public void run() {
  10. for(;;) {
  11. i++;
  12. yield();
  13. }
  14. }
  15. }
  16. class MultipleThreads {
  17. public static void main(String[] args) throws IOException {
  18. Incrementer u = new Incrementer();
  19. u.start();
  20. System.out.println("Repeatedly press a key to get the current value of i");
  21. for(;;) {
  22. System.in.read();
  23. System.out.println(u.i);
  24. }
  25. }
  26. }
  27. Run this
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:27: error: class, interface, or enum expected
Run this
^
1 error
stdout
Standard output is empty