Last active
August 29, 2015 14:14
-
-
Save kineticz/bbbd2f307714f3203b54 to your computer and use it in GitHub Desktop.
why aren't the x's printed when PrintNum reaches 50?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package je3.thread; | |
| /** | |
| * Created by IDEA on 01/02/15. | |
| */ | |
| public class PrintChar implements Runnable { | |
| private char charToPrint; | |
| private int times; | |
| public PrintChar(char c, int t) { | |
| charToPrint = c; | |
| times = t; | |
| } | |
| public PrintChar(char b) { | |
| this(b, 100); | |
| } | |
| @Override | |
| public void run() { | |
| for(int i = 0; i < times; i++) { | |
| System.out.print(charToPrint); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package je3.thread; | |
| /** | |
| * Created by IDEA on 01/02/15. | |
| */ | |
| public class PrintNum implements Runnable { | |
| private int lastNum; | |
| public PrintNum(int n) { | |
| lastNum = n; | |
| } | |
| @Override | |
| public void run() { | |
| Thread thread4 = new Thread( | |
| new PrintChar('x', 40) | |
| ); | |
| try { | |
| for (int i = 1; i <= lastNum; i++) { | |
| System.out.print(i + " "); | |
| if(i == 50) { | |
| thread4.join(); | |
| } | |
| } | |
| } | |
| catch (InterruptedException e) {} | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment