Space for google add

Define a thread called “PrintText_Thread” for printing text on command prompt for n number of times.

 



1. Define a thread called “PrintText_Thread” for printing text on command prompt for

n number of times. Create three threads and run them. Pass the text and n as
parameters to the thread constructor. Example:
i. First thread prints “I am in FY” 10 times
ii. Second thread prints “I am in SY” 20 times
iii. Third thread prints “I am in TY” 30 times

import java.io.*;
class PrintText_Thread extends Thread
{
    String s=null;
    int n;
    PrintText_Thread(String s,int n)
    {
        this.s=s;
        this.n=n;
           
    }
        public void run()
    {
        try
        {
            for(int i=1;i<=n;i++)
            {
                System.out.println(s+""+i+"times");
            }
        }
            catch(Exception e)
            {
                System.out.println(e);
            }
    }
}

class seta
{
    public static void main(String args[])
    {
        int n=Integer.parseInt(args[0]);
        PrintText_Thread t1=new PrintText_Thread("I am in FY",n);
        t1.start();
        PrintText_Thread t2=new PrintText_Thread("I am in SY",n+10);
        t2.start();
        PrintText_Thread t3=new PrintText_Thread("I am in TY",n+20);
        t3.start();
       
    }
}

Post a Comment

0 Comments