JAVA Program using Threads to Print Table of 20 and Even Numbers up to 100

JAVA Program using Threads to Print Table of 20 and Even Numbers up to 100:

import java.io.*;
class table extends Thread
{
 public void run()
 {
   int t=0;
   int n=20;
   for(int i=1;i<=10;i++)
   {
     t=n*i;
      System.out.println(n+"*"+i+"="+t);
   }
 }
}

class even extends Thread
{
 public void run()
 {

   for(int i=20;i<=100;i++)
   {
       if(i%2==0)
       {
    System.out.println(i);
       }
   }
  }
}
class thread2
{
    public static void main(String args[])
    {
        table t=new table();
        t.start();
        t.setPriority(Thread.MAX_PRIORITY);
        even e=new even();
        e.setPriority(Thread.MIN_PRIORITY);
        e.start();

    }
}

OUTPUT:

20*1=20
20*2=40
20*3=60
20*4=80
20*5=100
20*6=120
20*7=140
20*8=160
20*9=180
20*10=200
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.