java程序设计实验报告

上传人:第*** 文档编号:34258873 上传时间:2018-02-22 格式:DOC 页数:17 大小:134.91KB
返回 下载 相关 举报
java程序设计实验报告_第1页
第1页 / 共17页
java程序设计实验报告_第2页
第2页 / 共17页
java程序设计实验报告_第3页
第3页 / 共17页
java程序设计实验报告_第4页
第4页 / 共17页
java程序设计实验报告_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《java程序设计实验报告》由会员分享,可在线阅读,更多相关《java程序设计实验报告(17页珍藏版)》请在金锄头文库上搜索。

1、Java 程序设计实验报告学号: 姓名: 座位号: 实验日期:【实验名称】: JDK 配置与开发工具的使用【实验目的】:1 熟悉 JDK 开发环境。2 熟悉 EditPlus 编辑器或 Eclipse 等开发环境的使用。3 掌握 Java Application 的程序结构和开发过程。【实验内容及要求】:1 JDK 安装。2 设置环境变量。3 分别运用 EditPlus 和 Eclipse 编写并运行一个简单的“Hello World!”应用程序。 【程序输出结果与结果分析】:Helloworld【自评分及理由,自己的体会和收获】:主要是熟悉 jdk 的开发环境,环境变量的设置。Editplu

2、s 需要设置环境变量,eclipse 不用Path 的环境变量设置 C:EditPlusjdk1.6.0binClasspath 的环境变量的设置.;C:EditPlusjdk1.6.0bin【程序代码】:Editplus:class Helloworld public static void main(String args)System.out.println(Helloworld);Eclipse:public class HelloWorld public static void main(String args)System.out.println(Helloworld);Java

3、程序设计实验报告学号: 姓名: 座位号: 实验日期:【实验名称】: 类和对象的应用【实验目的】:1 掌握各种数据类型及其使用方法。2 掌握分支语句 if、switch 和循环语句 for、while、do-while 的应用。3 掌握类的声明和对象的创建。4 掌握方法的定义、调用和构造器的使用。【实验内容及要求】:1 分别使用 if-else-if 语句和 switch 语句编程,确定某一月在哪个季节。2 分别使用 while、do-while 和 for 语句编程,求 1100 的和。3 使用 break 语句实现记数:从 1100,当数到 78 时程序终止。4 编程创建一个 Box 类,在

4、其中定义三个变量表示一个立方体的长、宽和高,再定义一个方法 setDemo 对这三个变量进行初始化,然后定义一个方法求立方体的体积。创建一个对象,求给定尺寸的立方体的体积。【程序输出结果与结果分析】:一* 确定季节 * 1.if-else-if * 2.switch * 3.exit *请选择:1请输入当前月份:2该月为春季* 确定季节 * 1.if-else-if * 2.switch * 3.exit *请选择:2请输入当前月份:6该月为夏季* 确定季节 * 1.if-else-if * 2.switch * 3.exit *请选择:二1到 100的数字和: 5050三1234567891

5、01112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778四请输入Box的长:2请输入Box的宽:5请输入Box的高:4Box的长为:2Box的宽为:5Box的高为:4Box的体积为:40【自评分及理由,自己的体会和收获】:Editplus 当有输入时无法运行,Eclipse 可行【程序代码】:1 import java.util.Scanner;public class Test

6、1 /* 季节:* 1.if-else-if语句* 2.switch语句*/public static void main(String args) while (true) Scanner scan = new Scanner(System.in);System.out.println(* 确定季节 * );System.out.println(* 1.if-else-if *);System.out.println(* 2.switch *);System.out.println(* 3.exit *);System.out.println(*);System.out.print(请选择:

7、);int select = scan.nextInt();switch (select) case 1:IfSeason.decide();break;case 2:SwitchSeason.decide();break;case 3:System.exit(0);break;default:System.out.println(您输入的选项 有误);/调用工具 类utils 中的reset函数判断是否重新输入boolean select1 = utils.reset();if (select1) break; else System.exit(0);/if-else-ifclass IfS

8、easonpublic static void decide()while (true) /调用工具类utils中的input函数输入月份int month = utils.input();if (month=2|month=3|month=4) System.out.println(该月为春季nn);break; else if (month=5|month=6|month=7) System.out.println(该月为夏季nn);break; else if (month=8|month=9|month=10) System.out.println(该月为秋季nn);break; el

9、se if (month=11|month=12|month=1) System.out.println(该月为冬季nn);break; else System.out.println(您输入的月份有 误);/调用工具 类utils 中的reset函数判断是否重新输入boolean select = utils.reset();if (select) /跳出本次循 环continue; else /跳出 while循环break;/switchclass SwitchSeasonpublic static void decide()out: while (true) /调用工具类utils中的

10、input函数输入月份int month = utils.input();switch (month) case 2:case 3:case 4:System.out.println(该月为春季nn);break out;case 5:case 6:case 7:System.out.println(该月为夏季nn);break out;case 8:case 9:case 10:System.out.println(该月为秋季nn);break out;case 11:case 12:case 1:System.out.println(该月为冬季nn);break out;default:S

11、ystem.out.println(您输入的月份有 误);/调用工具 类utils 中的reset函数判断是否重新输入boolean select = utils.reset();if (select) /跳出本次循 环continue out; else /跳出 while循环break out;/工具 类class utils/输入当前月份public static int input()Scanner scan = new Scanner(System.in);System.out.print(请输入当前月份:);int month = scan.nextInt();return mon

12、th;/是否重新 输入public static boolean reset()System.out.println(是否重新输入?(Y/N):);Scanner scan = new Scanner(System.in);String select = scan.next().trim();if (Y.equals(select) return true;elsereturn false;2(1 )class Sum public static void main(String args) int i=1;int s=0;while(i=100)s=s+i;i+;System.out.pri

13、ntln(1到100的数字和:+s);(2)class Sum1 public static void main(String args) int s=0;for(int i=1;i=100;i+)s=s+i;System.out.println(1到100数字的和: +s);(3)class Sum2 public static void main(String args) int i=1;int s=0;dos=s+i;i+;while(i=100);System.out.println(1到100的数字的和:+s);3public class BreakTest /* param arg

14、s*/public static void main(String args) for (int i = 1; i = 100; i+) System.out.println(i);/print(i+rn)if (i=78) break;4import java.util.Scanner;public class BoxTest /* param args*/public static void main(String args) Scanner scan = new Scanner(System.in);Box box = new Box();System.out.print(请输入Box的长:);box.setLength(scan.nextInt();System.out.print(请输入Box的宽:);box.setWidth(scan.nextInt();System.out.print(请输入Box的高:);box.setHeight(scan.nextInt();System.out.println(nBox的长为: +box.getLength();System.out.println(Box的宽为:+box.getWidth();System.out.printl

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号