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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

Java书上及实验内容编程答案.docx

1、Java书上及实验内容编程答案51页第3题 /3、求水仙花数public class Test public static void main(String args) for(int i =100 ; i = 1); sum = sum + k; i+; while(i = 100); System.out.println(1!+2!+.+100! = +sum); /Rectangle类:(第80面2)public class Rectangle double width; double length; Rectangle(double l,double w) check(w,l); wi

2、dth = w ; length = l ; public void check(double w,double l) if(w50|l50) System.out.print(长或宽超出规定范围!); System.exit(0); public double getArea() return this.length*this.width; public double getPerimeter() return (this.length+this.width)*2; public void Draw() for(int i = 1 ; i = this.width ; i+) for(int

3、 j = 1 ; j = this.length ; j+) if(i = 1|i = this.width) System.out.print(*); else if(j = 1| j=this.length) System.out.print(*); else System.out.print( ); System.out.print(n); /Test测试类:public class Test public static void main(String args) Rectangle rec = new Rectangle(10,5); System.out.println(面积:+r

4、ec.getArea(); System.out.println(周长:+rec.getPerimeter(); rec.Draw(); /Area接口(第116面2)public interface Area double CalsulateArea(); /MyCircle类public class MyCircle implements Area double radius; final double PI = 3.1415926; public MyCircle(double r) radius = r; public double CalsulateArea() return PI*

5、radius*radius; /MyRectangle类public class MyRectangle implements Areadouble width,height; public MyRectangle(double w , double h) width = w; height = h; public double CalsulateArea() return width*height; /Test测试类public class Test public static void main(String args) MyRectangle m = new MyRectangle(5,

6、6); MyCircle m1 = new MyCircle(10); System.out.println(正方形m的面积:+m.CalsulateArea()+n圆形m1的面积:+m1.CalsulateArea();151页题3public class Test public static void main(String args)int table = 4,1,3,5,9,2,1;/初始化;for(int i = 0; i table.length; i+) System.out.print(tablei+t);/未改变时输出; System.out.print(n); for(in

7、t i = 0; i table.length/2; i+)/进行变换; int temp; temp = tablei; tablei = tabletable.length-1-i; tabletable.length-1-i = temp; for(int i = 0; i 0) y = Math.sqrt(b*b-4*a*c); x1=(-b+y)/(2*a); x2=(-b-y)/(2*a); System.out.println(这个一元二次多项式有两个不相等的实根为:x1 =+x1+,x2 = +x2); else System.out.println(这个一元二次多项式方程无实

8、数解。); 实验3题2实验4题4class account int leftmoney; String id; public int getleftmoney() return leftmoney;public void savemoney(double money)leftmoney+=money;public void getmoney(double money)if(money=leftmoney)leftmoney-=money;elseSystem.out.println(只能取:+leftmoney); public static void main(String args) ac

9、count aa=new account(); aa.leftmoney=0; aa.id=1234567899; aa.savemoney(21000); System.out.println(存入21000元后余额为:+aa.getleftmoney(); aa.getmoney(11500); System.out.println(11500元后余额为:+aa.getleftmoney(); 实验6题1import java.util.HashMap;import java.util.Scanner;class Book public String name; public double

10、 price; public int num;public static class Num1 public static double getSum(HashMap books) double sum=0; for(int i=0;ibooks.size();i+) Book b=books.get(i); sum+=b.price*b.num; return sum; public static void main(String args) HashMap m=new HashMap(); System.out.println(输入5本书的名称、单价、购买数量:n); for(int i=

11、0;i5;i+) Book b=new Book(); Scanner a=new Scanner(System.in); b.name=a.nextLine(); b.price=a.nextDouble(); b.num=a.nextInt(); m.put(i,b); double sum=getSum(m); System.out.println(sum=+sum); 实验9题3的时刻是光标离开第一个文本框。package bag;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Te

12、xtFieldtest extends JFrame public static void main(String args) JFrame frame=new TextFieldtest(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); JTextField first=new JTextField(); JTextField second=new JTextField(); JTextField result=new JTextField(); int n,m; TextFiel

13、dtest() super(TextFieldTest); setBounds(250, 200, 400, 200); setLayout(new FlowLayout(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); first=new JTextField(input integer1); second=new JTextField(input integer2); result=new JTextField(Get the Result); /添加鼠标事件,使鼠标离开first时候检查*/ first.addMouseListener

14、(new MouseHander(first); second.addMouseListener(new MouseHander(second); result.addMouseListener(new MouseHander(result); /添加鼠标事件,方便输入数据和计算结果 result.addMouseMotionListener(new MouseMotionHander(); second.addMouseMotionListener(new MouseMotionHander(); first.setColumns(30); second.setColumns(30); re

15、sult.setColumns(30); add(first); add(second); add(result); private class MouseHander extends MouseAdapter public MouseHander(JTextField c) current=c; public void mousePressed(MouseEvent event) if(current=result) double firstNumber=Double.parseDouble(first.getText(); double secondNumber=Double.parseD

16、ouble(second.getText(); double Result=firstNumber+secondNumber; result.setText(+Result); else current.setText(); private JTextField current; private class MouseMotionHander extends MouseMotionAdapter public void mouseMoved(MouseEvent event) double number=Double.parseDouble(first.getText(); if(number200) int type=JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(null,new String(输入数字必须在100200之间),提示, 2);

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

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