开启两个线程,一个线程打印1到100的奇数。如1,3,7…99. 另外一个线程打印1到100的偶数。如2,4,6…100.
1到100的数字最终打印出来格式是1,2,3,4,5…100.**
static int count = 0;
static SingletonDemo1 s = new SingletonDemo1();
public static void main(String[] args) {
new Thread(new Runnable() {
public void run() {
synchronized (s) {
while(count<=100) {
System.out.println(count++);
s.notify();
}
try {
s.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();