判斷兩整形數字大小,不用判斷語句

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

}

 

都是介於牛A和牛C之間的方法,哈哈。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章