2个最接近0的数字
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2个最接近0的数字相关的知识,希望对你有一定的参考价值。
Looking forward for the most optimized solution for the same
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ public var arr:Array = new Array("-23", "-12", "45", "22", "-42", "87", "97", "13","24","-10", "-2", "5") public function init():void{ arr.sort(Array.NUMERIC); for(var i=0;i<arr.length;i++){ txt.text += " "+arr[i]; if(arr[i]<0) { var min:Number = arr[i]; } if(arr[arr.length -i-1]>0){ var max:Number = arr[arr.length -i-1]; } } txt.text += " closet +ive number to 0>> "+max+" << closest -ive number to 0 >>"+min; } ]]> </mx:Script> <mx:TextArea x="118" y="57" width="553" height="412" id="txt"/> </mx:Application>
以上是关于2个最接近0的数字的主要内容,如果未能解决你的问题,请参考以下文章