ImageVerifierCode 换一换
你正在下载:

编程.docx

[预览]
格式:DOCX , 页数:20 ,大小:18.16KB ,
资源ID:6576247      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6576247.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(编程.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

编程.docx

1、编程833/*-【程序设计】-题目:使用while循环和if语句实现计算并输出1-100的偶数和,循环变量名为i,存放和的变量名为sum-*/public class Prog1/*Program*/ public static void main(String args) int i=1,sum=0; while(i=100) if(i%2=0) sum+=i; i+; System.out.println(sum); /* End */834/*-【程序设计】-题目:使用while循环和if语句实现计算并输出1-100的能被3整除的数的和,循环变量名为i,存放和的变量名为sum。-*/pu

2、blic class Prog1/*Program*/ public static void main(String args) int i=1,sum=0; while(i=100) if(i%3=0) sum+=i; i+; System.out.println(sum); /* End */835/*-【程序设计】-题目:使用for循环和if语句实现输出1到100中能被7整除或者个位数是7的数字,循环变量名为i-*/public class Prog1/*Program*/ public static void main(String args) int i; for(i=1;i=100

3、;i+) if(i%7=0 | i/100=7 | i/10/10=7 | i%10=7) System.out.println(i); /* End */836/*-【程序设计】-题目:编写一个应用程序,应用for循环计算整数n的阶乘,n的初始值为8,并将结果输出,循环变量名为i,存放阶乘的变量名为p-*/public class Prog1/*Program*/ public static void main(String agrs) int i,n=8,p=1; for(i=1;i=n;i+) p*=i; System.out.println(p); /* End */837/*-【程序

4、设计】-题目:使用while循环和if语句实现计算并输出1-100的奇数和,循环变量名为i,存放和的变量名为sum-*/public class Prog1/*Program*/ public static void main(String args) int i=1,sum=0; while(i=100) if(i%2!=0) sum+=i; i+; System.out.println(sum); /* End */838/*-【程序设计】-题目:Prog1类与对象1) 属性:两个double成员变量,width和height;2) 不带参数的构造方法:width和height的初始值分别

5、是6和8;3) 方法:计算并输出矩形的周长方法名为findPremeter ();4) 创建一个Prog1类的对象,对象名为r,调用findPremeter方法。-*/public class Prog1/*Program*/ private double width,height; public Prog1() this.width=6; this.height=8; public double findPremeter() return 2*(width+height); public static void main(String args) Prog1 r =new Prog1();

6、r.findPremeter(); /* End */839/*-【程序设计】-题目:属性有平时成绩(pingshi),期末成绩(qimo),都为int类型;不带参数的构造方法,方法有计算并输出总成绩的方法calculateScore(),计算方式为:总成绩=平时成绩+期末成绩的1/2;创建Prog1对象s,然后调用calculateScore()方法来输出总成绩。-*/public class Prog1/*Program*/ private int pingshi,qimo; public Prog1() this.pingshi=40; this.qimo=90; public doub

7、le calculateScore() return pingshi+qimo/2; public static void main(String args) Prog1 s=new Prog1(); System.out.println(s.calculateScore(); /* End */*-【程序设计】-题目:包含一个名为radius属性,类型为int,不带参数的构造方法和计算并输出面积方法findArea(面积=3.14*radius*radius),创建Prog1类的一个对象c,调用findArea方法。-*/public class Prog1/*Program*/ priva

8、te int radius; public Prog1() this.radius=4; public double findArea() return 3.14*radius*radius; public static void main(String args) Prog1 c=new Prog1(); c.findArea(); /* End */841/*-【程序设计】-题目:属性包括name(书名,String类型)、author(作者名,String类型)、price(书的价格,double类型),定义不带参数的构造方法,定义输出图书基本信息的show方法。创建Prog1类的一个对

9、象b,调用show方法。-*/public class Prog1/*Program*/ private String name,author; private double price; public Prog1() this.name=Core Java; this.author=Gary Cornell; this.price=52.8; public void show() System.out.println(The book name is +name+,author is +author+,the price is +price+.); public static void ma

10、in(String args) Prog1 b=new Prog1(); b.show(); /* End */842/*-【程序设计】-题目:定义类,属性包括商品名称name(String)、商品编号id(String)和价格price(double)三个属性,有无参的构造方法和计算折扣价格并输出的方法,方法头为public void computeDiscout(double percent),其中形参代表打折的百分比。创建商品类的对象,调用计算折扣价格的方法。-*/public class Prog1/*Program*/ private String name,id; private

11、double price; public Prog1() this.name=Shen Bao; this.id=23333333; this.price=52; public void computeDiscout(double percent) this.price*=(1-percent); public static void main(String args) Prog1 shop=new Prog1(); puteDiscout(0.2); /* End */843/*-【程序设计】-题目:现有父类Person,在此基础上派生出子类Teacher,子类定义了自己的属性String类

12、型的教师编号(teacherID),有不带参数的构造方法,覆盖了父类的print方法,调用父类被覆盖的print方法,增加打印自己的属性的语句,请实现Teacher类的编写。-*/class Person String id; String name; Person(String id, String name) this.id = id; this.name = name; void print() System.out.println(id = + id + ,name = + name); class Teacher extends Person /*Program*/ String t

13、eacherID; public Teacher() this.name=Shampoo; this.teacherID=23333; public void print() super.print(); System.out.println(teacherID = + teacherID + ,name = + name); /* End */public class Prog1public static void main(String args) 844/*-【程序设计】-题目:现有父类Person,在此基础上派生出子类Student,子类定义了自己的属性String类型的学号(stud

14、entID),有不带参数的构造方法,覆盖了父类的print方法,调用父类被覆盖的print方法,增加打印自己的属性的语句,请不实现Student类的编写。-*/class Person String id; String name; Person(String id, String name) this.id = id; this.name = name; void print() System.out.println(id = + id + ,name = + name); class Student extends Person /*Program*/ String studentID;

15、public Student() this.name=Shampoo; this.studentID=23333; public void print() super.print(); System.out.println(studentID = + studentID + ,name = + name); /* End */public class Prog1public static void main(String args)845/*-【程序设计】-题目:现有父类Good,在此基础上派生出子类Milk,子类定义了自己的属性double类型的会员价格(vipPrice),有带参数的构造方

16、法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,请实现Milk类的编写-*/class Goods double unitPrice;/单价 double account;/数量 Goods(double unitPrice, double account) this.unitPrice=unitPrice ; this.account=account ; double totalPrice() /计算总价格 return unitPrice * account; void show() System.out.println(单价是 + unitPrice

17、); System.out.println(购买数量为 + account); System.out.println(购买商品的总金额是 + this.totalPrice(); class Milk extends Goods /*Program*/ double vipPrice; public Milk(double unitPrice, double account,double vipPrice) this.unitPrice=unitPrice; this.account=account ; this.vipPrice=vipPrice; public void show() su

18、per.show(); System.out.println(会员价格为 + vipPrice); /* End */public class Prog1public static void main(String args)846/*-【程序设计】-题目:现有父类Good,在此基础上派生出子类Apple,子类定义了自己的属性String 类型的类别(kind),有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,请实现Apple类的编写。-*/class Goods double unitPrice;/单价 double account;/数

19、量 Goods(double unitPrice, double account) this.unitPrice=unitPrice ; this.account=account ; double totalPrice() /计算总价格 return unitPrice * account; void show() System.out.println(单价是 + unitPrice); System.out.println(购买数量为 + account); System.out.println(购买商品的总金额是 + this.totalPrice(); class Apple extends Goods /*Program*/ String kind; public Apple(double unitPrice, double account,String kind) this.unitPrice=unitPrice; this.account=account ; this.kind=kind; public void show() super.show(); System.out.println(类别为 + kind); /* E

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1