跳大神也是一种艺术:
public class MaxMin {
static int max = 0 ;
public static void main(String[] args) throws InterruptedException {
MaxMin m = new MaxMin();
int a = m.max(9, 10);
System.out.println("最大:"+a);
}
public int max(int a , int b ) throws InterruptedException{
new MyThread(a,this).start();
new MyThread(b,this).start();
Thread.sleep((a+b));
return this.max;
}
}
class MyThread extends Thread{
public int f = 0;
public MaxMin max ;
MyThread(int f , MaxMin max){
this.f=f;
this.max = max;
}
public void run() {
try {sleep(f);} catch (Exception e) {}
max.max = f;
}
}