欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

最大公约数

程序员文章站 2024-03-22 09:23:34
...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="12" fontFamily="Georgia">
<mx:Script>
<![CDATA[
import mx.controls.TextArea;

private function gongyueshu(txt1:String, txt2:String):String
{
var a1:int=parseInt(txt1);
var a2:int=parseInt(txt2);
//trace(a1);
var a:int=Math.max(a1, a2);
var b:int=Math.min(a1, a2);
var r:int=1;
//注:%是取模操作
while (r > 0)
{
r=a % b;
a=b;
b=r;
}

var res:String=a.toString();

return res
}
]]>
</mx:Script>
<mx:Panel title="最大公约数计算" width="394" height="351" horizontalAlign="center" layout="vertical" fontFamily="Verdana" fontSize="14">
<mx:HBox width="362" height="100%">
<mx:ApplicationControlBar dock="true" width="100%" height="100%" fillAlphas="[1.0, 1.0]" fillColors="[#F5F9E2, #F3FCCC]">
<mx:VBox height="257" width="220" fontSize="14" themeColor="#05578B" backgroundAlpha="0.0" borderColor="#F8F8F8" borderStyle="solid" borderThickness="0" fontFamily="Times New Roman">
<mx:Label text="数字1" width="100" color="#3C130B" alpha="1.0"/>
<mx:TextArea text="1" textAlign="right" id="text1" height="29" width="100" change="text3.text=gongyueshu(text1.text,text2.text)"/>
<mx:Label text="数字2" width="100"/>
<mx:TextArea text="2" textAlign="right" id="text2" height="28" width="100" change="text3.text=gongyueshu(text1.text,text2.text)"/>
<mx:Label text="结果" width="100"/>
<mx:TextArea text="3" textAlign="right" id="text3" height="28" width="100" borderColor="#000406" themeColor="#85C3EA" color="#F7C8C4" backgroundColor="#0A092A"/>
<mx:HRule width="202" height="0" strokeColor="#0E0C70"/>
<mx:Button label="数字1、2的最大公约数" click="text3.text=gongyueshu(text1.text,text2.text)" textAlign="center" width="200" id="button2" fontWeight="normal"/>
</mx:VBox>
</mx:ApplicationControlBar>
</mx:HBox>
</mx:Panel>
</mx:Application>

相关标签: XML