TY_BCS_A_JAVA_SLIP11



SLIP 11:
Define a thread called “PrintTextThread” for printing text on command prompt for ‘n’ number of times. Create 3 threads and run them. Pass the text ‘n’ parameters to the thread constructor.
Example:
a.    First thread prints “I am in FY” 10 times.
b.     Second thread prints “I am in SY” 20 times 
T     Third thread prints “I am in TY” 30 times   

/*SLIP11*/
import java.io.*;
import java.lang.String.*;

class Ass_seta3 extends Thread
{
            String msg="";
                        int  n;
                        Ass_seta3(String msg,int n)
                        {
                                    this.msg=msg;
                                                this.n=n;
                        }
            public void run()
            {
                        try
                        {           for(int i=1;i<=n;i++)
                                    {
                                                System.out.println(msg+" "+i+" times");
                                    }
                                    System.out.println("\n ");
                        }
                        catch(Exception e){}
            }
}
class Slip11_2
{
            public static void main(String a[])
            {
                        int n=Integer.parseInt(a[0]);
                                    Ass_seta3 t1=new Ass_seta3("I am in FY",n);
                                    t1.start();
                                    Ass_seta3 t2=new Ass_seta3("I am in SY",n+10);
                                    t2.start();
                                    Ass_seta3 t3=new Ass_seta3("I am in TY",n+20);
                                    t3.start();
            }
}

1 comment: