Write the thread program -1 using Runnable interface.
class PrintChar implements Runnable {
private char charToPrint;
private int times;
PrintChar(char c, int t) {
charToPrint = c;
times = t;
}
public void run() {
for (int i = 0; i < times; i++) {
System.out.print(charToPrint);
}
}
}
class PrintNumber implements Runnable {
private int n;
PrintNumber(int n) {
this.n = n;
}
public void run() {
for (int i = 1; i <= n; i++) {
System.out.print(i + " ");
}
}
}
public class Main {
public static void main(String[] args) {
Runnable charTask1 = new PrintChar('a', 100);
Runnable charTask2 = new PrintChar('b', 100);
Runnable numberTask = new PrintNumber(100);
Thread thread1 = new Thread(charTask1);
Thread thread2 = new Thread(charTask2);
Thread thread3 = new Thread(numberTask);
thread1.start();
thread2.start();
thread3.start();
}
}