import java.util.Random;
import java.util.Scanner;
public class Number {
public static void main(String[] args) {
// TODO Auto-generated method stub
Number1 proNum =new Number1();
Thread tPro =new Thread(proNum);
tPro.run();
try {
Thread.sleep(10);
Number1 gNum =new Number1 ();
Thread tGue =new Thread(gNum);
while(true) {
tGue.interrupt();
tGue.run();
Thread.sleep(10);
tPro.interrupt();
if(gNum.getNum()==proNum.getNum())
{
System.out.println("猜的数字为:"+gNum.getNum()+"猜对了");
break;
}
else if(gNum.getNum()<proNum.getNum())
System.out.println("猜的数字为:"+gNum.getNum()+"猜小了");
else
System.out.println("猜的数字为:"+gNum.getNum()+"猜大了");
}
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
}
class Number1 implements Runnable{
int num;
public synchronized void run() {
Random n =new Random();
num=n.nextInt(100);
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num=num;
}
}