📄 帮妹妹做的java作业(最大公约数,最小公倍数)_st_洛洛亚的blog_新浪博客.htm
字号:
href="http://blog.sina.com.cn/s/">小</A></SPAN> <SPAN class=title>正文</SPAN> <SPAN
class=ARTICLE_HOT></SPAN></DIV>
<DIV class="componentContent article">
<DIV class=articleTitle>
<DIV style="DISPLAY: inline"><B
id=t_4ab199630100061t>帮妹妹做的java作业(最大公约数,最小公倍数)</B> <SPAN class=time>(2006-10-13
12:15:24)</SPAN> </DIV></DIV>
<DIV class=articleTag>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<SCRIPT> var $tag=''; var $tag_code='82d4f01ffa194995f3c34a18a3fb9266'; </SCRIPT>
</TD>
<TD vAlign=top align=right width=225>分类:<A
href="http://blog.sina.com.cn/s/articlelist_1253153123_1_1.html">学习小结</A></TD></TR></TBODY></TABLE></DIV>
<DIV class=articleContent id=articleBody>
<DIV>类A完成最大公约数求解,然后类B利用A中的对象,得出最小公倍数。</DIV>
<DIV> <WBR></DIV>
<DIV>这是类A:</DIV>
<DIV> <WBR></DIV>
<DIV>package practice_3;</DIV>
<DIV>import javax.swing.JOptionPane;</DIV>
<DIV>public class
A<BR>{<BR>//最大公约数:A能被B整除,就说B是A的约数.两个数它所有的公约数中,最大的那个数就是它们的最大公约数.<BR> <WBR><BR> <WBR>static
int a;<BR> <WBR>static int b;<BR> <WBR><BR> <WBR>public void
getCoefficient()<BR> <WBR>{<BR> <WBR> <WBR>JOptionPane.showMessageDialog(null,"Please
input two number(must be int) and ensure that a must not smaller than
b");<BR> <WBR> <WBR>a=Integer.parseInt(JOptionPane.showInputDialog("Please
input the value of
a"));<BR> <WBR> <WBR>b=Integer.parseInt(JOptionPane.showInputDialog("Please
input the value of b"));<BR> <WBR>}<BR> <WBR><BR> <WBR>public int
doMax(int a,int b) <WBR> <WBR> <WBR>
//利用辗转相除法求解。每次把a%b的余数付给b,然后把b付给a,如此往复,就可以求得最大公约数。<BR> <WBR>{<BR> <WBR> <WBR>int
Max=0;<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
if(b==0) return a;<BR> <WBR> <WBR>else return
doMax(b,a%b);<BR> <WBR>}<BR> <WBR><BR> <WBR>public static void
main(String[] args)<BR> <WBR>{<BR> <WBR> <WBR>A max=new
A();<BR> <WBR> <WBR>max.getCoefficient();<BR> <WBR> <WBR>JOptionPane.showMessageDialog(null,"最大公约数是:"+max.doMax(a,b));<BR> <WBR>}</DIV>
<DIV>}<BR></DIV>
<DIV>这是类B:</DIV>
<DIV> <WBR></DIV>
<DIV>package practice_3;<BR>import javax.swing.JOptionPane;<BR>public class
B<BR>{<BR>/*最小公倍数算法<BR> <WBR>几个共有的倍数,叫做这几个数的公倍数,其中最小的一个,叫做这几个数的最小公倍数。<BR> <WBR>要找的是数要既是A的倍数,也是B的倍数.显然A*B是满足的,不过它虽然是公倍数,但不一定是最小的.<BR> <WBR>当求出最大公约数D后,相当与A/D与B/D互质,它们的最小公倍数为它们的乘积A/D*B/D.<BR> <WBR>所以A,B的最小公倍数是A/D*B/D*D=(A*B)/D<BR>*/<BR> <WBR>int
a,b,c,result;<BR> <WBR><BR> <WBR>public void
getCoefficient()<BR> <WBR>{<BR> <WBR> <WBR>JOptionPane.showMessageDialog(null,"Please
input two number(must be int) and please ensure a must not smaller than
b");<BR> <WBR> <WBR>a=Integer.parseInt(JOptionPane.showInputDialog("Please
input the value of
a"));<BR> <WBR> <WBR>b=Integer.parseInt(JOptionPane.showInputDialog("Please
input the value of b"));<BR> <WBR>}<BR> <WBR><BR> <WBR>public int
doMin() <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
//求解最小公倍数;<BR> <WBR>{<BR> <WBR> <WBR>A min=new
A(); <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
//创建一个A类的实例;<BR> <WBR> <WBR>c=min.doMax(a,
b); <WBR> <WBR> <WBR> <WBR> <WBR>
//完成作业要求,B类中的变量c是A中的对象;<BR> <WBR> <WBR>result=(a*b)/c;<BR> <WBR> <WBR>return
result;<BR> <WBR>}<BR> <WBR>public static void main(String[]
args)<BR> <WBR>{<BR> <WBR> <WBR>B x=new
B();<BR> <WBR> <WBR>x.getCoefficient();<BR> <WBR> <WBR>JOptionPane.showMessageDialog(null,"最小公倍数是:"+x.doMin()); <WBR><BR> <WBR>}</DIV>
<DIV>}<BR></DIV>
<DIV> <WBR></DIV></DIV>
<DIV class=articleInfo><!--(<a href="http://my2008.sina.com.cn/blog/rule.html" target="_blank">规则</a>)<span class="space12"></span>(<a href="#" onclick="return false;"><span onclick="showMyRecord();">积分</span></a>) <span class="space12"></span>//--></DIV>
<DIV class=articleUtil>
<DIV class=floatRight><A
href="http://blog.sina.com.cn/s/blog_4ab199630100061t.html#comment">评论</A><SPAN
class=sub id=c_4ab199630100061t>(0)</SPAN><SPAN class=space>|</SPAN> <A>阅读</A>
<SPAN class=sub id=r_4ab199630100061t>(0)</SPAN> <SPAN class=space>|</SPAN> <A
id=f_4ab199630100061t
onclick="$articleManage('4ab199630100061t',5);return false;"
href="http://blog.sina.com.cn/s/">收藏</A> <SPAN class=sub
id=fn_4ab199630100061t>(0)</SPAN> <SPAN class=space>|</SPAN> <A
id=s_4ab199630100061t onclick="addShare('4ab199630100061t');return false;"
href="http://blog.sina.com.cn/s/">分享</A> <SPAN class=space>|</SPAN> <A
href="http://blog.sina.com.cn/main_v5/ria/print.html?blog_id=blog_4ab199630100061t"
target=_blank>打印</A> <SPAN class=space>|</SPAN> <A id=q_4ab199630100061t
onclick="window.open('http://control.blog.sina.com.cn/admin/advice/impeach.php?url=4ab199630100061t' , '', 'height=495, width=510, left=' + (window.screen.width-538)/2 + ',top=' + (window.screen.height-525)/2, toolbar='no', menubar='no', scrollbars='no', resizable='no' , status='no');return false;"
href="javascript:;">举报</A> </DIV></DIV>
<DIV class=articleContext>前一篇:<SPAN class=space6></SPAN><A
href="http://blog.sina.com.cn/s/blog_4ab199630100060s.html~type=v5_one&label=rela_prevarticle">又有一个朋友要走了,昨天我又喝醉了</A><BR>后一篇:<SPAN
class=space6></SPAN><A
href="http://blog.sina.com.cn/s/blog_4ab199630100061u.html~type=v5_one&label=rela_nextarticle">格式化小数点后位数</A>
</DIV>
<DIV class="sinaPlan SinaAd_hide" id=advertise_bottom></DIV>
<DIV class=comment id=blogCommentArea>
<DIV class=commentBar><SPAN class=floatLeft><SPAN
class=title>评论 </SPAN><SPAN class=my2008
id=COMMENT_FIRST_HOT></SPAN></SPAN> <SPAN class=floatRight><A
href="http://blog.sina.com.cn/s/blog_4ab199630100061t.html#post">发表评论</A></SPAN>
</DIV>
<DIV class=commentContent><A name=comment></A>
<DIV id=commentContent></DIV>
<DIV class=commentBottom id=commentPaging></DIV><!-- <div class="sinaPlan"> <span class="floatLeft title hot"></span> <span class="floatRight manage"><a href="#"></a></span> </div> --><A
name=post></A>
<DIV class=commentBar><SPAN class=floatLeft><SPAN
class=title>发表评论 </SPAN><SPAN id=COMMENT_HOT></SPAN></SPAN>
</SPAN></DIV>
<DIV class=sendComment>
<TABLE width=640>
<TBODY>
<TR>
<TD class=info align=left><SPAN id=comment_login_form
style="DISPLAY: none">登录名:<INPUT class=username id=login_name>密码:<INPUT
class=password id=login_pass type=password><A
href="http://login.sina.com.cn/getpass.html" target=_blank>找回密码</A> <A
href="http://login.sina.com.cn/hd/reg.php?entry=space"
target=_blank>注册新浪通行证</A></SPAN> <SPAN id=comment_wel></SPAN><SPAN
id=anonymity_wel style="DISPLAY: none">昵称:<INPUT class=username
id=anonymity_name value=新浪网友></SPAN> </TD>
<TD align=right><SPAN id=comment_anon><INPUT id=anonymity type=checkbox
value="" name="">匿名评论(无需注册)</SPAN> </TD></TR></TBODY></TABLE>
<DIV id=emotioins></DIV><TEXTAREA class=commentArea id=commentArea></TEXTAREA>
<DIV>验证码:<INPUT class=checkwd id=login_check><IMG id=comment_check_img
alt=看不清楚数字吗?点击这里再试试。
src="帮妹妹做的java作业(最大公约数,最小公倍数)_st_洛洛亚的BLOG_新浪博客.files/checkwd_image.png"
align=absMiddle border=0><SPAN id=audioCheckCon></SPAN></DIV>
<DIV class=sendBut><INPUT class="but_all but_3" id=comment_post_btn type=submit value=发评论>
</DIV></DIV></DIV></DIV></DIV>
<DIV class=componentBottom></DIV></DIV></DIV></DIV>
<DIV class=clear ?></DIV></DIV>
<DIV class=sinaBottom>
<CENTER><A href="http://control.blog.sina.com.cn/admin/advice/advice_list.php"
target=_blank>新浪BLOG意见反馈留言板</A> <A
onclick="window.open ('http://control.blog.sina.com.cn/admin/advice/impeach.php?url=' + escape(document.location.href), '', 'height=495, width=510, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no');"
href="javascript:;">不良信息反馈</A> 电话:95105670 提示音后按2键(按当地市话标准计费) 欢迎批评指正 </CENTER>
<P><A href="http://corp.sina.com.cn/chn/" target=_blank>新浪简介</A> | <A
href="http://corp.sina.com.cn/eng/" target=_blank>About Sina</A> | <A
href="http://ads.sina.com.cn/" target=_blank>广告服务</A> | <A
href="http://www.sina.com.cn/contactus.html" target=_blank>联系我们</A> | <A
href="http://corp.sina.com.cn/chn/sina_job.html" target=_blank>招聘信息</A> | <A
href="http://www.sina.com.cn/intro/lawfirm.shtml" target=_blank>网站律师</A> | <A
href="http://english.sina.com/" target=_blank>SINA English</A> | <A
href="http://members.sina.com.cn/apply/" target=_blank>会员注册</A> | <A
href="http://tech.sina.com.cn/focus/sinahelp.shtml" target=_blank>产品答疑</A> </P>
<P class=copyright>Copyright © 1996 - 2008 SINA Corporation, All Rights Reserved
<BR></P>
<DIV>新浪公司 <A href="http://www.sina.com.cn/intro/copyright.shtml"
target=_blank>版权所有</A></DIV></DIV></DIV><SPAN style="DISPLAY: none" expara=""
url="http://blog.sina.com.cn/s/blog_4ab199630100061t.html"
key="4ab199630100061t" pid="1" name="pvcounter"></SPAN>
<SCRIPT id=PVCOUNTER_FORIE type=text/javascript></SCRIPT>
<SCRIPT src="帮妹妹做的java作业(最大公约数,最小公倍数)_st_洛洛亚的BLOG_新浪博客.files/pvcounter.js"
type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>loadResource();</SCRIPT>
<SCRIPT type=text/javascript>renderBlog();</SCRIPT>
<SCRIPT src="帮妹妹做的java作业(最大公约数,最小公倍数)_st_洛洛亚的BLOG_新浪博客.files/680.js"
type=text/javascript></SCRIPT>
<SCRIPT language=javascript>
if($UID!=null)
{
dwScript({url:"http://v.space.sina.com.cn/visitor/add.php?prod=1&uid=" + $uid + "&vid=" + $UID + "&var=newVisitor"});
}
</SCRIPT>
<!-- SUDA_CODE_START -->
<SCRIPT src="帮妹妹做的java作业(最大公约数,最小公倍数)_st_洛洛亚的BLOG_新浪博客.files/suda_s_v851c.js"
type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
//<!--
try{
var config_pic = config?(config.s?((config.s.head || config.s.head)?((config.s.head.usepic || config.s.bg.usepic)?((config.s.head.usepic=='1')||(config.s.bg.usepic=='1')?1:0):0):0):0):0;
_S_pSt(_S_PID_,config.s.t,config.s.r+","+config_pic);
}catch(e){}
//-->
</SCRIPT>
<!-- SUDA_CODE_END --><!-- START WRating v1.0 -->
<SCRIPT src="帮妹妹做的java作业(最大公约数,最小公倍数)_st_洛洛亚的BLOG_新浪博客.files/a1.js"
type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
try{
var vjAcc="860010-0328010000";
var wrUrl="http://sina.wrating.com/";
vjTrack("");
}catch(e){};
</SCRIPT>
<NOSCRIPT><IMG style="DISPLAY: none" height=1 src="" width=1></NOSCRIPT> <!-- END WRating v1.0 --></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -