Answer to Question #268473 in Java | JSP | JSF for dhyfullah

Question #268473



Write a program that contains three threads. The first reads a letter and repeats the display of lines of increasing number of that letter. The second and third threads will do the same with other letters. Run this program which executes these threads simultaneously. The program and an output of a sample run are required.


Notice :use java language +I need the program to be in one class

An Execution Sample:

A

AA

AAA

B

BB

BBB

C

CC

CCC

AAAA

AAAAA

AAAAAA

BBBB

BBBBB

BBBBBB

CCCC

CCCCC

CCCCCC


1
Expert's answer
2021-11-19T17:15:10-0500
class RunnableDemo implements Runnable {
   private Thread t;
   private char ch;
   private int start;
   private int stop;
   
  RunnableDemo(char c,int st,int sp) {
      ch=c;
      start=st;
      stop=sp;
  }
   
   public void run() {
        for(int i=start;i<=stop;i++){
		    for(int j=0;j<=i;j++){
		        System.out.print(ch+" ");
		    }
		    System.out.println();
		}
            Thread.sleep(50);
        }
       
   }
   
   public void start () {
      if (t == null) {
         t = new Thread (this, ch,start,stop);
         t.start ();
      }
   }
}


public class Main {


   public static void main(String args[]) {
      RunnableDemo R1 = new RunnableDemo('A',1,4);
      R1.start();
      
      RunnableDemo R2 = new RunnableDemo('B',1,4);
      R2.start();
      RunnableDemo R3 = new RunnableDemo('C',1,4);
      R3.start();
   }   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS