Two Threads Print 1 10 1 Thread Prints Odd 1 Thread Prints Even Hi Need Assignment Starter Q28359053

Two threads; Print 1 – 10; 1 thread prints odd; 1 thread printseven Hi I need to do this assignment this my starter codes but Ineed to print two threads with above mentioned instructions if someone can help me out. public class TaskThreadDemo3 { public staticvoid main(String[] args) { // Create tasks Runnable printA = newPrintChar(‘a’, 100); Runnable printB = new PrintChar(‘b’, 100);Runnable print100 = new PrintNum(100); // Create threads Threadthread1 = new Thread(printA); Thread thread2 = new Thread(printB);Thread thread3 = new Thread(print100); // Start threadsthread1.start(); thread2.start(); thread3.start(); } } // The taskfor printing a specified character in specified times classPrintChar implements Runnable { private char charToPrint; // Thecharacter to print private int times; // The times to repeat /**Construct a task with specified character and number of * times toprint the character */ public PrintChar(char c, int t) {charToPrint = c; times = t; } /** Override the run() method to tellthe system * what the task to perform */ public void run() { for(int i = 0; i < times; i++) { System.out.print(charToPrint); } }} // The task class for printing number from 1 to n for a given nclass PrintNum implements Runnable { private int lastNum; /**Construct a task for printing 1, 2, … i */ public PrintNum(int n){ lastNum = n; } /** Tell the thread how to run */ public voidrun() { for (int i = 1; i <= lastNum; i++) { System.out.print(“” + i); } } }

“We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help”

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.