想要用多线程打印出12A34B56C78D.......
但是像这样写只能打出12,notify没有起作用,请问如何改动
public class 作业2
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
new Thread(new Number()).start();
new Thread(new Letter()).start();
}
}
class Number implements Runnable
{
private int n = 1;
@Override
public synchronized void run()
{
for (int i = 0; i < 52; i++)
{
if (i % 2 == 0 && i != 0)
{
try
{
notify();;
this.wait();
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.print(n + i);
}
}
}
class Letter implements Runnable
{
char a = 'a';
@Override
public synchronized void run()
{
try
{
wait();
} catch (InterruptedException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (int i = 0; i < 26; i++)
{
System.out.print(a + i);
try
{
notify();
this.wait();
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}