网站大量收购闲置独家精品文档,联系QQ:2885784924

JAVA大学实用教程(第二版)附课后练习答案 第5章 继承、接口与泛型.ppt

JAVA大学实用教程(第二版)附课后练习答案 第5章 继承、接口与泛型.ppt

  1. 1、本文档共144页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JAVA大学实用教程(第二版)附课后练习答案 第5章 继承、接口与泛型

* * * * * * * * * * * * * * * * * * * * * * * * * * * * 第五章 问答题 return message; } } class MaxCommonDivisor{ public int getMaxCommonDivisor(int a, int b)throws NegativeIntegerException{ if(a0||b0) throw new NegativeIntegerException(); 第五章 问答题 int r=0; if(ab){ int t=a; a=b; b=t; } r=a%b; while(r!=0){ a=b; 第五章 问答题 b=r; r=a%b; } return b; } } class MinCommonMultiple extends MaxCommonDivisor{ public int getMinCommonMultiple(int a, int b)throws NegativeIntegerException{ 第五章 问答题 if(a0||b0) throw new NegativeIntegerException(); int y=0; int x=getMaxCommonDivisor(a,b); y=(a*b)/x; return y; 第五章 问答题 } } public class Example{ public static void main (String arg[]){ int maxCommonDivisor, minCommonMultiple; MaxCommonDivisor max=new MaxCommonDivisor(); 第五章 问答题 MinCommonMultiple min = new MinCommonMultiple(); try{ maxCommonDivisor=max.getMaxCommonDivisor(18,12); 第五章 问答题 System.out.println(最大公约数:+ maxCommonDivisor); minCommonMultiple=min.getMinCommonMultiple(18,12); System.out.println(最小公倍数:+minCommonMultiple); maxCommonDivisor=max.getMaxCommonDivisor(-64,48); 第五章 问答题 System.out.println(最大公约数:+maxCommonDivisor); } catch(NegativeIntegerException e){ System.out.println(e.toString()); } } } 第五章 作业题 3。编写一个类要求实现一个接口,该接口有3个abstract方法: Public abstract void f( int x); Public abstract void g(int x, int y); Public abstract double h(double x); 要求在应用程序主类中使用该类创建对象,并使用接口回调调用方法f(), g() 和h(). 第五章 作业题 3. interface A{ public abstract void f(int x); public abstract void g(int x,int y); public abstract double h(double x); } 第五章 作业题 class A1 implements A{ public void f(int x){ System.out.println(x); } public void g(int x,int y){ int z=x+y; System.out.println(z

文档评论(0)

2017meng + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档