太原理工大学Java实验报告_第1页
太原理工大学Java实验报告_第2页
太原理工大学Java实验报告_第3页
太原理工大学Java实验报告_第4页
太原理工大学Java实验报告_第5页
已阅读5页,还剩119页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实验由本人当时亲自完成 仅供参考,希望可以帮助大家本科实验报告课程名称:java 程序设计 b实验项目:java 语言基础编程和面向对象设计实验地点:逸夫楼 501专业班级:0000学号:00000000学生姓名:氣宇軒昂指导教师:2012 年13 月13 日精选文库实验名称 实验目的和要求实验一java 环境搭建和 java 语言基础编程.掌握 jdk、eclipse 的下载和安装,并熟练使用 api 帮助文档;学会 java application 程序和 java applet 程序的编制、编译和运行; 熟练掌握 java 程序流程控制语句的使用;熟练掌握 java 语言数

2、组的使用、字符串以及字符串处理方法的使用。实验内容1. 下载并安装最新版本的 jdk 和 eclipse,设置环境变量,下载 api 帮助文档。2. 设计 java application 程序,输出“我叫,我编写的 java application 程序运 行通过了”,分别在命令提示符和 eclipse 环境中编译、运行。.完成习题 2.7 的编程、调试与运行。 使用 for 循环语句输出习题 3.5 中的图案。 完成习题 3.9 的编程、调试与运行。 完成习题 4.5 和 4.7 的编程、调试与运行。主要仪器设备台式或笔记本计算机实验记录 (写出实验内容中 3,5,6 的程序

3、代码和运行结果 )(可分栏或加页 ) 2.7 程序代码import java.util.scanner;public class datatypepublic static void main(string args)scanner in=new scanner(system.in);system.out.print(请输入一个long型数据(输完按enter结束):); long a=in.nextlong();system.out.print(请输入一个float型数据(输完按enter结束):); float b=in.nextfloat();system.out.print(请输入一个

4、double型数据(输完按enter结束):); double c=in.nextdouble();system.out.println(long:+a);system.out.println(float:+b);system.out.println(double:+c);运行结果2精选文库3.9 程序代码import java.util.scanner;public class valueforeint n;valuefore()this.n=calculaten();double stackby(int n)int i;double s=1;for(i=1;i=n;i+)s*=i;retu

5、rn s;double overlap()int i;double sum=1;for(i=1;ia)3精选文库i+;return i;public static void main(string args)scanner in=new scanner(system.in);boolean b=true;while(b)system.out.println(请选择菜单:);system.out.println( 1.计算不同精度的e值);system.out.println( 2.退出);switch(in.nextbyte()case 1:system.out.println(请输入精度(例

6、如:1e-3,表示0.001):); valuefore a=new valuefore();system.out.println(e=+a.overlap();break;case 2:b=false;break;运行结果说明:没有按书中的要求去求,但是这个程序功能更强,运用了菜单的方式,使用程序的人能求4精选文库出不同精度的 e 值。4.5 程序代码public class stringtextpublic static void main(string args)string str1=i am;string str2=a student;string str3=我是中国人;string

7、buffer str=new stringbuffer();str.append(str1).append(str2).append(str3);system.out.println(str);system.out.println(str.charat(8);system.out.println(str.charat(16);运行结果4.7 程序代码import java.util.scanner;public class trianglevoid printtriangle(int row)int i,j;int a=new introw; for(i=0;irow;i+)ai=new in

8、ti+1;for(i=0;irow;i+)ai0=1;aii=1;for(i=2;irow;i+)for(j=1;ji;j+)5精选文库aij=ai-1j-1+ai-1j;system.out.println(输出杨辉三角为:); for(i=0;ii;j-)system.out.print(t);for(j=0;jb?a:(bc?b:c);return this.max;public double seekmin(double a,double b,double c)10精选文库this.min=ab?a:(bc?b:c);return this.min;package mymaths;im

9、port java.util.scanner;public class examplepublic static void main(string args)scanner in=new scanner(system.in);maxminvalue num = new seekmaxminvalue();boolean a=true;while(a)system.out.println(请选择菜单:);system.out.println( 1.取最大值);system.out.println( 2.取最小值);system.out.println( 3.退出);switch(in.nextb

10、yte()case 1:system.out.print(输入要比较的三个数并用空格隔开:);system.out.println(max=+num.seekmax(in.nextdouble(),in.nextdouble(),in .nextdouble();break;case 2:system.out.print(输入要比较的三个数并用空格隔开:);system.out.println(min=+num.seekmin(in.nextdouble(),in.nextdouble(),in .nextdouble();break;case 3:a=false;break;运行结果11精选

11、文库说明:有些繁琐,但根据提示进行就可以了实验五内容(三)程序:import java.util.scanner;public class bankstring name;long remainder;bank(string name,long remainder)=name;this.remainder=remainder;long withdraeal(long getmoney) throws insufficientfundsexceptiontrythis.remainder=this.remainder-getmoney;if(this.remainder18)

12、);bt4=new jbutton(退出);bt1.addactionlistener( this );bt2.addactionlistener( this );bt3.addactionlistener( this );bt4.addactionlistener( this );container con=getcontentpane();con.setlayout( new flowlayout();con.add( bt1 );con.add( bt2 );con.add( bt3 );con.add( bt4 );精选文库31精选文库container container=getco

13、ntentpane();container.add( new jscrollpane( table),borderlayout. center); setvisible( true);validate();addwindowlistener( new windowadapter()public void closing(windowevent e)system. exit(0););overridepublic void actionperformed(actionevent e) / todo auto-generated method stubif(e.getsource()= bt1)w

14、hile(i=0)/ 清空上次查询结果ai0=;ai1=;ai2=;ai3=;ai4=;i-;i=0;try class. forname (sun.jdbc.odbc.jdbcodbcdriver ); catch (classnotfoundexception e1) / todo auto-generated catch blocke1.printstacktrace();tryconn =drivermanager. getconnection (jdbc:odbc:sqlserver ); stm =conn.createstatement();rs=stm.executequery( select * from dbo.student );while(rs.next()string id= rs.getstring( 学号);string name= rs.getstri

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论