Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ShareString extends Thread {
- private static String printed = "";
- private final String letter;
- private final int sec;
- public ShareString(String letter, int sec) {
- this.letter = letter; this.sec = sec;
- }
- @Override
- public void run() {
- while (true) {
- append();
- try { sleep(sec * 1000); }
- catch (Exception e) { e.printStackTrace(); }
- }
- }
- private void append() {
- if (printed.endsWith("いう")) {
- System.out.println("え"); System.exit(0);
- }
- System.out.print(letter); printed += letter;
- }
- public static void main(String[] args) {
- ShareString s1 = new ShareString("あ", 2);
- ShareString s2 = new ShareString("い", 3);
- ShareString s3 = new ShareString("う", 4);
- s1.start(); s2.start(); s3.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement