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. /**
  9.  * Created by jigar.joshi on 8/27/14.
  10.  */
  11.  
  12. import java.util.Scanner;
  13.  
  14. class IdeOne extends Thread {
  15. private boolean done = false;
  16. String message = "";
  17. private volatile boolean isRead = true;
  18.  
  19. public boolean isRead() {
  20. return isRead;
  21. }
  22.  
  23. public void setRead(boolean isRead) {
  24. this.isRead = isRead;
  25. }
  26.  
  27. public void run() {
  28. while (!isDone()) {
  29. while (isRead()) {
  30. System.out.println("Please enter the advertisement message to be displayed (enter 'n' to exit):");
  31. Scanner sc2 = new Scanner(System.in);
  32. message = sc2.nextLine();
  33. if (message.equalsIgnoreCase("n")) {
  34. done = true;
  35. System.out.println("User Stopped the Message Output");
  36. setRead(false);
  37. System.out.println("Terminating");
  38. System.exit(0);
  39. continue;
  40. }
  41. setRead(false);
  42. }
  43. while (!(isInterrupted())) {
  44. try {
  45. System.out.print("** " + message + " **");
  46. Thread.sleep(1000);
  47. } catch (InterruptedException e) {
  48. System.out.println("Exception caught: " + e.getMessage());
  49. done = false;
  50. break;
  51. }
  52. }
  53. }
  54.  
  55. }// end of 'run()' ..
  56.  
  57. /**
  58.   * @return the done
  59.   */
  60. public boolean isDone() {
  61. return done;
  62. }
  63.  
  64. public static void main(String ar[]) {
  65. IdeOne advt = new IdeOne();
  66. advt.start();
  67. Scanner sc = new Scanner(System.in);
  68. while (true) {
  69. while (!advt.isRead()) {
  70. System.out.println("main listening");
  71. String str = sc.nextLine();
  72. if (str.equals("\n")) {
  73. System.out.println("new line detected");
  74. advt.interrupt();
  75. }
  76. advt.setRead(true);
  77. }
  78. }
  79. }
  80. }
Compilation error #stdin compilation error #stdout 5s 381568KB
stdin
Standard input is empty
compilation info
Main.java:33: error: cannot find symbol
                    done = true;
                    ^
  symbol:   variable done
  location: class IdeOne
Main.java:48: error: cannot find symbol
                    done = false;
                    ^
  symbol:   variable done
  location: class IdeOne
Main.java:60: error: cannot find symbol
        return done;
               ^
  symbol:   variable done
  location: class IdeOne
3 errors
stdout
Standard output is empty