读书人

回答: 不用判断语句求俩数中的大(或者

发布时间: 2012-11-04 10:42:42 作者: rapoo

答复: 不用判断语句求俩数中的大(或者小)数
跳大神也是一种艺术:

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;}}
啊哈哈哈哈, 这文章幽默,收了 } catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
System.out.println("最大" + b);
}
}

}} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
System.out.println("最大" + b);
}
}

}
似乎这个执行起来效率更高,不过都是介于牛A和牛B之间的写法。 15 楼 zhanghh321 2011-06-08 如果是两个负数怎么办呢?

读书人网 >其他相关

热点推荐