Sunday, 3 July 2016

Write a Java program to create two threads T1 and T2. Thread T1 is having priority six and thread T2 is having default priority assigned to it. Implement threads T1 and T2 in such a way that T1 prints table of 2 and T2 prints table of 5

class T1 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"2"+"="+i*2);
}
}

class T2 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"5"+"="+i*5);
}
}


public class T3 {
 
    public static void main(String[] args){
 
    T1 t1=new T1();
    T2 t2=new T2();
    t1.setPriority(6);
    t1.start();
    t2.start();
    }
 
}

OUTPUT:

1*2=2
2*2=4
3*2=6
4*2=8
5*2=10
6*2=12
7*2=14
8*2=16
9*2=18
10*2=20
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50

1 comment:

  1. thank u so much for your valuable comment... I'll try my best to more improvement...

    ReplyDelete

Popular Posts