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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

javaWord格式.docx

1、+(s+i);4. 当从命令提示符输入数字112时,按照如下格式输出:请输入月份:5 month= 5,该月有31天import java.util.Scanner;public class month public static void main(String args) Scanner sc = new Scanner(System.in); int i = sc.nextInt();n if(i12|i1) System.out.println(输入信息有误! else switch(i) case 1: case 3: case 5: case 7: case 8: case 10:

2、 case 12:System.out.println(month=+i+该月有31天break; case 4: case 6: case 9: case 11:该月有30天 case 2:该月有28天 5. 求一组数中的最大值和最小值。import java.util.Random;public class compare public static int random(int n) int table=new intn; for(int i=0;table.length;i+) tablei=(int)(Math.random()*100); return table;public s

3、tatic void print(int table) for(int i=0; +tablei); System.out.println();public static void compare(int table) int max,min; max=table0; min=table0; int temp=new int2;for(int i=1; if(maxtablei) min=tablei; temp0=max; temp1=min; System.out.println(max=+temp0);min=+temp1); public static void main(String

4、 args) int b=random(10); System.out.print(table: print(b); compare(b); print( compare(b);6. 找出两个字符串中所有共同的字符。public class stringTestpublic static void main (String args) String str=I like java programming, java is good;int i1=str.indexOf(j String s1=str.substring(i1);String s2=str.substring(i1,i1+4);

5、 int i2=str.lastIndexOf(String s3=str.substring(i2+5);s1=+s1);s2=+s2);s3=+s3);7. 运行下面的程序,理解String类常用方法的使用。 public class stringTest public static void main (String args)String str= 8. 设计银行账户类,成员变量包括账号、储户姓名、开户时间、身份证号码、存款余额等账户信息,成员方法包括存款、取款等操作。public class bank int number,id; int year,month,day; float

6、money; String name; void set(int y,int m,int d) year=y; month=m; day=d; public String toString() return year+年+month+月+day+日 public float money1(int n) money=money+n; return money; public float money2(int x) if(moneyx) return 0; money=money-x; bank b=new bank(); b.set(2009,8,6); b.money=0; b.number=

7、1; b.id=20102; b.name=张三 System.out.println(用户名:+b.name);身份证号:+b.id);开户日期是:+b.toString();请输入存入的数额: Scanner sc = new Scanner(System.in); b.money1(i);账户余额:+b.money); System.out.println();请输入取款余额: Scanner cc = new Scanner(System.in); int j = cc.nextInt(); b.money2(j);9. 书名:* 作者:* 月销售量:*本public class bo

8、ok String name,autor; int number; public book() name=骆驼祥子 autor=老舍 number=200154; public book(String str1,String str2,int i) name=str1; autor=str2; number=i; public void setBook(String str1,String str2,int i) this.name=str1; this.autor=str2; this.number=i; public void printBook(book b) System.out.pr

9、intln(书名:+b.name+作者:+b.autor);月销售量+b.number+本 book d=new book(); d.printBook(d); book e=new book(童年,高尔基,20156); e.printBook(e); book f=new book(); f.setBook(在人间,20546); f.printBook(f); 10. 设计一个抽象类Graphics(图形类),包含私有成员变量shape(形状)、带参数的构造方法(确定该图形是什么形状)、用于计算面积的抽象方法area( )、用于显示面积的成员方法print( )。设计两个Graphics

10、类的子类:Rectangle类(矩形)和Circle类(圆),编译并运行使程序运行结果如下所示: 矩形的面积为: 100.0 圆的面积为: 314.159*93public abstract class Graphics private String shape; protected Graphics(String shape) this.shape=shape;public abstract double area();public void print() System.out.println(this.shape+的面积是:+this.area(); Graphics r=new Rec

11、tangle(5,20); r.print(); r=new Circle(10); class Rectangle extends Graphics protected double length; protected double width; public Rectangle(double length,double width) super(矩形 this.length=length; this.width=width;public Rectangle() this(0,0);public double area() return this.width*this.length; cla

12、ss Circle extends Graphics protected double radius; public Circle(double radius) super(圆 this.radius=radius; public Circle() this(0); public double area() return Math.PI*this.radius*this.radius;11. 定义一个接口Area,其中包含一个计算面积的抽象方法calculateArea(),然后分别设计MyCircle和MyRectangle两个类都实现这个接口中的方法calcualteArea(),分别计算

13、圆的面积和矩形的面积。 interface Area public abstract double calculateArea(); class MyRectangle implements Areapublic MyRectangle(double length,double width) this.length=length; this.width=width;public double calculateArea() return this.width*this.length;public MyRectangle() this(0,0);public String toString()

14、return 一个矩形,长度+length+,宽度+width+,面积为+calculateArea(); class MyCircle implements Area protected double r;public MyCircle(double r) this.r=r;public MyCircle() this(0); return Math.PI*this.r*this.r;圆,半径+r+public class test1 System.out.println(new MyRectangle(10,20).toString();System.out.println(new MyC

15、ircle(10).toString();14. 重新编写实验四的程序,要求将Circle类和Rectangle类放到不同的包中,用包的技术组织程序的设计。import com.package1.*; import com.package2.*;public class InterfaceArea public static void main(String args) MyRectangle a = new MyRectangle(30,10); MyCircle b = new MyCircle(10); System.out.println(a.calculateArea(); Syst

16、em.out.println(b.calculateArea(); package com.package1;interface Area public abstract double calculateArea();public class MyRectangle implements Area protected double width; public MyRectangle(double length,double width) this.length = length; this.width = width; public double calculateArea() return

17、this.width*this.length;package com.package2; import com.package2.Area;public class MyCircle implements Area public MyCircle(double radius) this.radius = radius; return Math.PI*radius*radius;15. 定义一个外部类Outer,包含属性姓名name和方法getInfo( ),在getInfo( )方法中包含两个属性年龄age和性别sex,并定义一个内部类Inner,在Inner内有sayHello( )方法,在

18、sayHello()方法中输出姓名、年龄和性别的信息。public class Outer private String name = Amumu private void getInfo() int age = 23; String sex=男 System.out.println(age); System.out.println(sex); class Inner void sayHello() System.out.println(name); getInfo(); Inner inner1 = new Inner(); public static void main(String ar

19、gs) Outer out= new Outer(); out.inner1.sayHello();16. 在程序中主动产生一个ArithmeticException类型被0除的异常,并用catch 语句捕获这个异常,最后调用ArithmeticException类的对象e的getMessage( )方法显示出异常的具体类型。public class error try int a = 0; a = 1/0;catch(ArithmeticException e) System.out.println(e.getMessage();17. 编写一个自定义的异常类,包含一个product( )方

20、法(用于两个数相乘),如果product( )方法中的两个参数的乘积小于0,则抛出一个自定义异常类的对象,输出错误信息和乘积的值。另外要求product( )方法要用throws关键字声明该方法要抛出自定义异常和算术异常。public class MyError extends Exception public MyError(String s) super(s); public MyError()class Error void product()throws MyError int a = -1; int b = 1; int c = a*b; if(c0) throw new MyErr

21、or(乘积小于零+c); Error ee = new Error(); try ee.product(); catch(MyError e) System.out.println(e.toString();18. 该窗口模拟Windows的计算器功能,添加一个文本行和4个按钮,单击【1】、【2】、【+】按钮时,将按钮的标签添加到文本行中;单击【C】按钮时,清空文本行中的内容;单击窗口的关闭按钮,将关闭该窗口import java.awt.*; import java.awt.event.*; import javax.swing.*;public class QueryFrame exten

22、ds JFrame implements ActionListener private TextField text_char; private Button button1,button2,buttonAdd,buttonc; private String str= public QueryFrame()calculator this.setBounds(280,100,300,240); this.setBackground(java.awt.Color.lightGray); this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT); text_char = new TextField(,10); this.add(text_char); button1 = new Button(1 this.add(button1); button1.addActionListener(this); button2 = new Button(2 this.add(button2); button2.addActionListener(this); buttonAdd = new Button( this.add(buttonAdd); buttonAdd.addActionListener(this); butt

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

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