最大公约数


<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值