Slip 4
/*Write a java program to display “Hello Java” message n times on the screen. (Use Runnable Interface). */
import java.io.*;
class Hellojava implements Runnable
{
Thread t;
public Hellojava(String title)
{
t=new Thread(this,title);
t.start();
}
public void run()
{
for(int i=0;i<20;i++)
{
System.out.println((i+1)+"ThreadName:"+Thread.currentThread().getName());
try
{
Thread.sleep(10000);
}
catch(Exception e)
{
}
}
}
}
public class Demotext
{
public static void main(String args[])
{
System.out.println("ThreadName : " +Thread.currentThread().getName());
Hellojava t1=new Hellojava("HELLO JAVA");
}
}
No comments:
Post a Comment