Advertisement
cd62131

ShareString

Jun 28th, 2014
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.81 KB | None | 0 0
  1. public class ShareString extends Thread {
  2.   private static String printed = "";
  3.   private final String letter;
  4.   private final int sec;
  5.  
  6.   public ShareString(String letter, int sec) {
  7.     this.letter = letter; this.sec = sec;
  8.   }
  9.  
  10.   @Override
  11.   public void run() {
  12.     while (true) {
  13.       append();
  14.       try { sleep(sec * 1000); }
  15.       catch (Exception e) { e.printStackTrace(); }
  16.     }
  17.   }
  18.  
  19.   private void append() {
  20.     if (printed.endsWith("いう")) {
  21.       System.out.println("え"); System.exit(0);
  22.     }
  23.     System.out.print(letter); printed += letter;
  24.   }
  25.  
  26.   public static void main(String[] args) {
  27.     ShareString s1 = new ShareString("あ", 2);
  28.     ShareString s2 = new ShareString("い", 3);
  29.     ShareString s3 = new ShareString("う", 4);
  30.     s1.start(); s2.start(); s3.start();
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement