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
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();
}
}
Comments
Leave a comment