天天看点

javaSE---最大值最小值和冒泡排序及随机数的讲解最大值最小值问题:冒泡排序:随机数的使用:

<a href="http://blog.51cto.com/attachment/201104/105141890.png" target="_blank"></a>

执行时,每次只要用一种方法就好了!其实,最大值最小值问题,就是先假定一个数是最大值或者最小值,然后用它和其他的数组元素分别比较,找出比他还大的或者还小的,最后就会找到最大值或者最小值!

说明:float max = heights[0];应该放到第一个for循环之后。

比如比五个人的身高(身高是知道的!)

<a href="http://blog.51cto.com/attachment/201104/111507929.png" target="_blank"></a>

举个例子:

<a href="http://blog.51cto.com/attachment/201104/110542565.png" target="_blank"></a>

另一种输出方法可以仿照刚才介绍的最大值和最小值问题的方法一输出!!

<a href="http://blog.51cto.com/attachment/201104/111024967.png" target="_blank"></a>

老师随机点名的程序,你自己可以试试!

<a href="http://blog.51cto.com/attachment/201104/111257178.png" target="_blank"></a>

      本文转自韩立伟 51CTO博客,原文链接:http://blog.51cto.com/hanchaohan/555414,如需转载请自行联系原作者

继续阅读