
public synchronized void set(String name, int age){
if(!flag){
try {
super.wait();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
this.name = name;
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
this.age = age;
flag = false;
super.notify();
}
public synchronized void get(){
if(flag){
try {
super.wait();
} catch (Exception e) {
// TODO: handle exception
}
}
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
System.out.println(this.getName()+"<===>"+this.getAge());
flag = true;
super.notify();
}
1.使用Scanner工具類來獲得用戶輸入的成績信息,Scanner類位于java.util中嘴瓤,使用時(shí)需要導(dǎo)入此包import java.util.Scanner; 2.創(chuàng)建...