版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、西 安 邮 电 大 学(计算机学院)面向对象程序设计JAVA 课内实验报告 实验名称: Java类库和常用类(二) 专业名称: 班 级: 学生姓名: 学号(8位): 指导教师: 实验时间: 1. 实验目的及实验环境实验目的: 1理解类库的概念,掌握分析、应用类库中的类的方法。 2熟练掌握Math类的常用方法。熟悉Random类的常用方法。 3理解String类的特性,熟练掌握String类的常用方法。 4能用Date类创建对象,熟练掌握Date类的常用方法。 5熟练掌握SimpleDateFormat解析日期和设置日期输出格式。 6学会查阅Java API在线参考文档和离线文档的方法。实验环境
2、:Eclipse for java2. 实验内容 1 基本内容(实验前请及时熟悉如下相关内容) 1)练习使用Math类的常用方法。 2)应用String类编程练习。 3)编写程序应用Random类生成随机数。 4)练习使用Date类的常用方法。 5)查阅Java API在线参考文档和下载Java API离线文档。 2 综合实验:2.1 (Y. Daniel Liang英文版八版P296:8.3*) (Using the Date class) Write a program that creates a Date object, sets its elapsed time to 10000,
3、100000, 10000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, and displays the date and time using the toString() method, respectively.2.2(Y. Daniel Liang英文版八版P296:8.4*) (Using the Random class) Write a program that creates a Random object with seed 1000 and displays the first 50 ran
4、dom integers between 0 and 100 using the nextInt(100) method.2.3 (Y. Daniel Liang英文版八版P296:8.5*) (Using the GregorianCalendar class) Java API has the GregorianCalendar class in the java.util package that can be used to obtain the year, month, and day of a date. The no-arg constructor constructs an i
5、nstance for the current date, and the methods get(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH), and get(GregorianCalendar.DAY_OF_MONTH) return the year, month, and day.Write a program to perform two tasks: Display the current year, month, and day. The GregorianCalendar class has the setTime
6、InMillis(long), which can be used to set a specified elapsed time since January 1, 1970. Set the value to 1234567898765L and display the year, month, and day.2.4(Y. Daniel Liang英文版八版P337:9.11*) (Sorting characters in a string) Write a method that returns a sorted string using the following header:pu
7、blic static String sort(String s)For example, sort("acb") returns abc.Write a test program that prompts the user to enter a string and displays the sorted string.2.5(Y. Daniel Liang英文版八版P338:9.15*) (Finding the number of uppercase letters in a string) Write a program that passes a string t
8、o the main method and displays the number of uppercase letters in a string.3 方案设计(核心代码和流程设计)四测试数据及运行结果1正常测试数据及运行结果;2正常测试数据及运行结果;3 正常测试数据及运行结果;4. 正常测试数据及运行结果5. 正常测试数据及运行结果五总结1 实验过程中遇到的问题及解决办法。2 对设计及调试过程的心得体会。6 附录:源代码(请把源代码按照实验内容附到其后)2_1 Using the Date classimport java.util.Date;import java.text.Simpl
9、eDateFormat;class toString public toString(long s) Date date = new Date(s); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str = format.format(date); System.out.println(str); public class DisplayDate public static void main(String args) toString str1 = new to
10、String(10000); toString str2 = new toString(100000); toString str3 = new toString(1000000); toString str4 = new toString(10000000); toString str5 = new toString(100000000); toString str6 = new toString(1000000000); toString str7 = new toString(10000000000L); toString str8 = new toString(100000000000
11、L); 2_2 Using the Random classimport java.util.*;public class RandomFigure public static void main(String args) Random rd = new Random(1000); for (int i=0; i<50; i+) int in = rd.nextInt(101); System.out.print(in + " "); 2_3 Using the GregorianCalendar classimport java.util.*;public clas
12、s PrintDate public static void main(String args) GregorianCalendar date = new GregorianCalendar(); int year1 = date.get(GregorianCalendar.YEAR); int month1 = date.get(GregorianCalendar.MONTH); int day1 = date.get(GregorianCalendar.DAY_OF_MONTH); System.out.println("当前日期: " + year1 + "
13、年" + month1 + "月" + day1 + "日"); date.setTimeInMillis(1234567898765L); int year2 = date.get(GregorianCalendar.YEAR); int month2 = date.get(GregorianCalendar.MONTH); int day2 = date.get(GregorianCalendar.DAY_OF_MONTH); System.out.println("特定日期: " + year2 + "年&q
14、uot; + month2 + "月" + day2 + "日"); 2_4 Sorting characters in a stringimport java.util.*;class StrSort public static String sort(String s) char str = s.toCharArray(); for (int i = 0; i < s.length(); i+) for (int j = 0; j < i; j+) if (stri < strj) char t = stri; stri = str
15、j; strj = t; return String.valueOf(str); public class StringSort public static void main(String args) System.out.print("Please input a string: ");Scanner s = new Scanner(System.in);String a = s.nextLine(); System.out.println("排序后的字符串: " + StrSort.sort(a); 2_5 Finding the number of uppercase letters in a stringimport java.util.*;public class PrintUpperNumber public static void main(String args) System.out.print("Please input a string: ");Scan
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026重庆大渡口区跃进村街道办事处街道聘用人员招聘1人笔试模拟试题及答案解析
- 2026年浦城县教师招聘考试模拟试题及答案解析
- 2026-贵州省安顺统计局招聘考试参考题库-含答案
- 2026武汉市疾病预防控制中心(预防医学服务中心)招聘眼视光师1人笔试备考试题及答案解析
- 2026-海南五指山文物保护中心招聘考试参考题库-含答案
- 2026-河南烟草公司人力资源专员招聘考试参考题库-含答案
- 2026广东江门市新会区人力资源和社会保障局“百万英才汇南粤”秋季招聘服务项目遴选考试模拟试题及答案解析
- 2026喀什地区中医医院面向社会公开招聘编制外工作人员45人笔试备考试题及答案解析
- 年薪10-20W!国昌实验学校招聘教师笔试参考题库及答案解析
- 2026年故城县教师招聘考试参考题库及答案解析
- 2026中国反渗透膜废弃量预测与绿色回收技术路线图
- 2025-2026学年风筝教学设计图片素材
- 《地球的“面纱”》教学设计-2026-2027学年青岛版四年级科学上册
- GB 48013-2026养老机构基本规范
- 完整版农田建设项目施工组织设计方案
- 2026增材制造用金属粉末球形度控制关键技术突破
- 2026年生态环境行政执法与刑事司法衔接竞赛
- 2025-2026学年统编版八年级道德与法治下册全册知识点
- 2026年特殊食品考核测试卷【必刷】附答案详解
- 云知账号案例分析(小约翰可汗)
- 三生公司直销培训课件
评论
0/150
提交评论