Question: Rewrite Listing 30.1 to display the output in a text area, as shown in Figure 30.30. Listing a 1b2b3b 4b 5 b6bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 7 8bbbbbbbbbbbbbbbbbbbb 9bb10

Rewrite Listing 30.1 to display the output in a text area, as shown in Figure 30.30.a 1b2b3b 4b 5 b6bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 7 8bbbbbbbbbbbbbbbbbbbb 9bb10 16 11 12 13

Listing

14 15 17 18 19 20 21 22 23 24 25 26

a 1b2b3b 4b 5 b6bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 7 8bbbbbbbbbbbbbbbbbbbb 9bb10 16 11 12 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99b 100bbbbbbbabaabbabaa baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb 1 public class TaskThreadDemo { public static void main(String[] args) { // Create tasks Runnable printA = new PrintChar('a', 100); Runnable printB = new PrintChar('b', 100); Runnable print100 - new PrintNum(100); 2 // Create threads Thread threadl = new Thread(printA); Thread thread2 = new Thread(printB); Thread thread3 = new Thread(print100); 10 11 12 // Start threads thread1.start(); thread2.start(); thread3.start(); 13 14 15 16 17 18 } 19 20 // The task for printing a character a specified number of times 21 class PrintChar implements Runnable { 22 23 private char charToPrint; // The character to print private int times; // The number of times to repeat 24 25 26 27 28 29 /** Construct a task with a specified character and number of * times to print the character */ public PrintChar(char c, int t) { charToPrint - c; times - t; 30 31 32 33 34 35 @Override /** Override the run() method to tell the system * what task to perform public void run() { for (int i = 0; i < times; i++) { System.out.print(charToPrint); 36 37 38 39 40 41 } 42 43 // The task class for printing numbers from 1 to n for a given n 44 class PrintNum implements Runnable { 45 46 private int lastNum; 47 /** Construct a task for printing 1, 2, n */ public PrintNum(int n) { lastNum = n; 48 49 50 51 52 53 @Override /** Tell the thread how to run */ public void run() { for (int i = 1; i = lastNum; i++) { System.out.print(" " + i); 54 55 56 57 58 }

Step by Step Solution

3.38 Rating (167 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program Plan Create PrintChar class so that prints a specified character a or b 100 times in a te... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!