/ Published in: ActionScript 3
Looking forward for the most optimized solution
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ var total:Number = 10; var primeArr:Array = new Array(); public function init():void{ var num:Number = total+1; var str:String; var i:Number=3; do{ if(primeNumber(i) == true) { primeArr.push(i); } i++; }while(primeArr.length<10) for(var j=0;j<primeArr.length;j++){ txt.text += "\n "+primeArr[j]; } } function primeNumber(num):Boolean { var bool:Boolean; var nums = Math.floor(Math.sqrt(num)); var i:Number = 1; bool = true; while (++i <= nums) { if ((num % i) == 0) { bool = false; i = nums; } } return bool; } ]]> </mx:Script> <mx:TextArea x="118" y="57" width="553" height="412" id="txt"/> </mx:Application>