Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Program 8:

import java.io.*;

class Two extends Thread

public void run()

for(int i = 1;i<=5;i++)

System.out.println(i+"*"+5+"="+(i*5));

System.out.println("\n End of First Thread.");

class Four extends Thread

public void run()

for(int i = 1;i<=4; i++)

System.out.println(i+"*"+4+"="+(i*4));

System.out.println("\n End of Second Thread.");

class Six extends Thread

public void run()

for(int i = 1;i<=8; i++)

System.out.println(i+"*"+8+"="+(i*8));

System.out.println("\n End of Third Thread.");


}

public class Multithreading

public static void main(String[] args)

Two a = new Two();

Four b = new Four();

Six c = new Six();

a.setPriority(Thread.MAX_PRIORITY);

b.setPriority(Thread.NORM_PRIORITY);

c.setPriority(Thread.MIN_PRIORITY);

a.start();

b.start();

c.start();

Output:

1*5=5

2*5=10

3*5=15

4*5=20

5*5=25

End of First Thread.

1*4=4

2*4=8

3*4=12

4*4=16

1*8=8

End of Second Thread.

2*8=16

3*8=24

4*8=32
5*8=40

6*8=48

7*8=56

8*8=64

End of Third Thread.

You might also like