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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

Java上机题目及答案代码Word格式文档下载.docx

1、 System.out.println(s1 = s2); System.out.println(s1 = s3); System.out.println(s1.length(); System.out.println(s1.equals(s2); System.out.println(s1.equals(s3); System.out.println(pareTo(s2); System.out.println(pareTo(s3); System.out.println(s1.concat(s3); System.out.println(s1.indexOf(t); System.out.

2、println(s3.lastIndexOf( 实验2 Java异常处理一、实验目的1)掌握Java异常的概念及工作机制2)掌握异常的分类3)掌握抛出异常语句的使用(throw)4)掌握抛出捕获处理异常语句的使用(trycatchfinally)5)掌握上抛异常语句的使用(throws)6)掌握创建自定义异常二、实验环境JDK1.6+Eclpise3.2三、实验内容1、编写一个应用程序,要求从键盘输入一个double型的圆的半径,计算并输出其面积。测试当输入的数据不是double型数据(如字符串“abc”)会产生什么结果,怎样处理。package lab2;import java.util.I

3、nputMismatchException;import java.util.Scanner;public class Err_1 Scanner reader=new Scanner(System.in); double r; try r=reader.nextDouble(); System.out.println(3.14*r*r); /System.out.println(3.14*r*r); catch(InputMismatchException e) System.out.println(数据类型错误+e.toString();2、计算两个正数之和,当任意一个数超出范围时,抛出自

4、己定义的异常(NumberRangeException)。import piler.sym;class NumberRangeException extends Exception NumberRangeException(String msg) super(msg);public class Err_2 int a=reader.nextInt(); int b=reader.nextInt(); if(a=0|b=0) NumberRangeException e=new NumberRangeException(The number beyond range!); throw e; Sy

5、stem.out.println(a+b); catch(NumberRangeException e) System.out.println(e.toString();实验3 输入和输出 1实验目的 了解流式输入输出的基本原理;掌握类、的使用方法。 2实验内容 (1)编程:检查C:WINDOWSsetuplog.txt文件是否存在,若在则显示该文件的名称和内容。package lab3;import java.io.File;import java.io.IOException;public class Inout private static Scanner in; public stat

6、ic void main(String args)throws IOException File(C:WINDOWSsetuplog.txt System.out.println(Do this ?t+f1.exists(); System.out.println(f1.getName(); in = new Scanner(new File( while (in.hasNextLine() String str = in.nextLine(); System.out.println(str); catch(IOException e) System.out.println(e.getMess

7、age();(2)编程:输入5个学生的信息(包含学号、姓名、3科成绩),统计各学生的总分,然后将学生信息和统计结果存入二进制数据文件STUDENT.DAT中。3实验要求 编程时,应考虑异常处理。import java.io.;import java.io.ObjectOutputStream;import java.io.RandomAccessFile;import javafx.beans.value.WritableObjectValue;class Student String snum; String name; int a,b,c,sum; public void Info()Pl

8、ease enter the name: name=reader.next();Please enter the student number: snum=reader.next();Please enter three coursessorce: a=reader.nextInt(); b=reader.nextInt(); c=reader.nextInt(); sum=a+b+c; reader.close();public class Inout_2 raf=new (dari.txt,true); ObjectOutputStream out=new ObjectOutputStre

9、am(raf); Student stu=new Student5; for(int i=0;i5;i+) stui=new Student(); (stui).Info(); out.writeObject(stui); out.close(); catch(IOException ioe) System.out.println(ioe); catch(Exception e) System.out.println(e);实验题目4设计计算器的GUI界面,理解使用Java中的布局管理器。package lab4;import java.awt.FlowLayout;import java.a

10、wt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.util.ArrayList;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextArea;public class MyFrame extends JFrame private JButton btn0=new J

11、Button(0 private JButton btn1=new JButton(1 private JButton btn2=new JButton(2 private JButton btn3=new JButton(3 private JButton btn4=new JButton(4 private JButton btn5=new JButton(5 private JButton btn6=new JButton(6 private JButton btn7=new JButton(7 private JButton btn8=new JButton(8 private JBu

12、tton btn9=new JButton(9 private JButton btnpoint=new JButton(. private JButton btnsqrt=new JButton( private JButton btnadd=new JButton(+ private JButton btnsub=new JButton(- private JButton btnmul=new JButton(* private JButton btndiv=new JButton(/ private JButton btnback=new JButton( private JButton

13、 btnsin=new JButton(sin private JButton btnequ=new JButton(= private JButton btnclear=new JButton(CE private JTextArea input=new JTextArea(2,21); private JTextArea show=new JTextArea(Result:n,2,21); private String result= private ArrayList signpos=new ArrayList(); public MyFrame(String title) this()

14、; setTitle(title); private MyFrame() setLayout(new FlowLayout(FlowLayout.LEADING); setSize(250, 250); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null);/ show.setEditable(false); input.setEditable(false); add(input); add(show); add(btn7); add(btn8); add

15、(btn9); add(btndiv); add(btnsqrt); add(btn4); add(btn5); add(btn6); add(btnmul); add(btnback); add(btn1); add(btn2); add(btn3); add(btnsub); add(btnclear); add(btn0); add(btnpoint); add(btnsin); add(btnadd); add(btnequ); btn0.addActionListener(new ActionListener() Override public void actionPerforme

16、d(ActionEvent e) input.setText(input.getText()+ ); btn1.addActionListener(new ActionListener() btn2.addActionListener(new ActionListener() btn3.addActionListener(new ActionListener() btn4.addActionListener(new ActionListener() btn5.addActionListener(new ActionListener() btn6.addActionListener(new Ac

17、tionListener() btn7.addActionListener(new ActionListener() btn8.addActionListener(new ActionListener() btn9.addActionListener(new ActionListener() btnpoint.addActionListener(new ActionListener() btnadd.addActionListener(new ActionListener() signpos.add(input.getText().length(); btnsub.addActionListe

18、ner(new ActionListener() btnmul.addActionListener(new ActionListener() btndiv.addActionListener(new ActionListener() btnsin.addActionListener(new ActionListener() double res; if(!input.getText().isEmpty()/!input.getText().equals() /!input.getText()= error! res=Double.parseDouble(input.getText(); sho

19、w.setText(sin +input.getText()+ = +Math.sin(res); input.setText( else if(!result.isEmpty() res=Double.parseDouble(result);+result+ btnequ.addActionListener(new ActionListener() String in=input.getText(); if(signpos.size()=0) return; double first; String tmp= if(in.charAt(0)=+|in.charAt(0)=-*/ first=Double.parseDouble(result); tmp=result.substring(result.indexOf(=)+1); else first=Double.parseDouble(in.substring(0, signpos.get(0); result=String.valueOf(operator(first,0,in); show.setText(tmp+in+result); signpos.clear(); btnsqrt.addActionListener(new ActionListener() public void acti

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

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