不用判断语句求两个数中的大(或小)数

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;
}
}




另一种方法是:


public class Check { 

public static void main(String[] args) {
int a = 11;
int b = 10;
Check check = new Check();
check.say(a, b);

}

public void say(int a, int b) {

int[] arrA = new int[a];
try {
arrA[b] = a;
System.out.println("最大" + arrA[b]);
} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
System.out.println("最大" + b);
}
}

}

你可能感兴趣的:(java,thread,F#)