12. 10. 24
import java.*;
import java.io.IOException;
class MyThread extends Thread
{
public void run()
{
for (int i = 0; i < 10; i++)
{
System.out.print((i + 1) + "");
}
}
}
class MyRunnable implements Runnable
{
String Name;
public MyRunnable()
{
Name = "";
}
public MyRunnable(String name)
{
Name = name;
}
public void run()
{
try
{
for (int i = 0;; i++)
{
String test = "Hello World!!";
// System.out.print(Name + i + " ");
System.out.print(test.charAt(i));
Thread.sleep(500);
if (test.length() == (i + 1))
break;
}
} catch (Exception e)
{
System.out.print(" Error ");
}
}
}
class MessageLoop implements Runnable
{
public void run()
{
String message[] =
{ "Pride will have a fall.",
"Power is dangerous unless you have humility.",
"Office changes manners.", "Empty vessels make the most sound." };
try
{
for (int i = 0; i < message.length; i++)
{
System.out.println(message[i]);
Thread.sleep(1000);
}
} catch (Exception e)
{
}
}
}
public class console
{
public static void main(String[] args) throws Exception
{
// Thread t = new MyThread();
// Thread t2 = new Thread(new MyRunnable("A"));
// Thread t3 = new Thread(new MyRunnable("B"));
Thread t4 = new Thread(new MessageLoop());
// t.start();
// t2.start();
// t3.start();
t4.start();
}
void print(String message)
{
String threadName = Thread.currentThread().getName();
System.out.format("%s: %s%n", threadName, message);
}
}