如何用一个打印口诀内容线程、一个打印tab("\t")线程和一个换行线程来打印99乘法表我先前用两个线程打印了99乘法表
代码如下:
class NewLine implements Runnable //换行线程
{
public void run()
{
while(true)
{
synchronized("str")
{
if(NumTable.stop) break;
System.out.println();
try
{
Thread.sleep(1);
}catch(InterruptedException e){}
}
}
}
}
public class NumTable implements Runnable
{
static boolean stop=false;
public void run()
{
for(int i=1;i<=9;i++)
{
synchronized("str")
{
for(int j=1;j<=i;++j)
{
System.out.print(j+"x"+i+"="+j*i+"\t");
}
try
{
Thread.sleep(10);
}catch(InterruptedException e){}
}
}
stop=true;
}
public static void main(String [] args)
{
new Thread(new NumTable()).start();
new Thread(new NewLine()).start();
}
}用3个线程来实现要考虑线程同步和通信问题,我花了好久也没能实现,请高手指点!!!!!!!!
代码如下:
class NewLine implements Runnable //换行线程
{
public void run()
{
while(true)
{
synchronized("str")
{
if(NumTable.stop) break;
System.out.println();
try
{
Thread.sleep(1);
}catch(InterruptedException e){}
}
}
}
}
public class NumTable implements Runnable
{
static boolean stop=false;
public void run()
{
for(int i=1;i<=9;i++)
{
synchronized("str")
{
for(int j=1;j<=i;++j)
{
System.out.print(j+"x"+i+"="+j*i+"\t");
}
try
{
Thread.sleep(10);
}catch(InterruptedException e){}
}
}
stop=true;
}
public static void main(String [] args)
{
new Thread(new NumTable()).start();
new Thread(new NewLine()).start();
}
}用3个线程来实现要考虑线程同步和通信问题,我花了好久也没能实现,请高手指点!!!!!!!!
解决方案 »
- java Graphics对象是如何创建的。他的构造方法是protected。
- main 方法所在的类一定需要实例化吗?
- 请各位大哥进来帮小弟个忙--参数传递
- 撒分~~技术问题高手来。不怕不会的。就找高手
- applet~~~~~~~
- 请问如何将java帮助文档加到我得工具jcreatorzhong!!!(急)
- 再谈hashtable
- geyf(其实我也不会) 及各位大侠,请再帮忙指点一下迷津!!!
- 关于Rethrowing异常
- <a href="#" title="真人发音" class="sp dictvoice voice-js log-js" data-rel="peninsu
- Unicode 如何转换为gb2312???
- 很简单的问题,但不知道你会不会?
---------------------
都是程序 为什么非要分不个不同呢 WaitForSingleObject这个API WINDOWS有的 JAVA也肯定要有 没有就没法做线程锁了 那JAVA的线程就是垃圾 这话对不对呢?