




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西 安 邮 电 大 学(计算机学院)面向对象程序设计JAVA 课内实验报告 实验名称: Java类库和常用类(二) 专业名称: 班 级: 学生姓名: 学号(8位): 指导教师: 实验时间: 1. 实验目的及实验环境实验目的: 1理解类库的概念,掌握分析、应用类库中的类的方法。 2熟练掌握Math类的常用方法。熟悉Random类的常用方法。 3理解String类的特性,熟练掌握String类的常用方法。 4能用Date类创建对象,熟练掌握Date类的常用方法。 5熟练掌握SimpleDateFormat解析日期和设置日期输出格式。 6学会查阅Java API在线参考文档和离线文档的方法。实验环境: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, 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 random 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 instance 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 setTimeInMillis(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:public 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 to 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.SimpleDateFormat;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 toString(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(100000000000L); 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; i50; i+) int in = rd.nextInt(101); System.out.print(in + ); 2_3 Using the GregorianCalendar classimport java.util.*;public class 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 + 年 + 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 + 年 + 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 = strj; 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 Print
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 年度消防安全培训记录课件
- 子宫肌瘤术前课件
- 年度安全教育培训记录课件
- 年度安全培训计划分解课件
- 年度安全再培训考核记录课件
- 威廉的洋娃娃课件
- 湖北公务员考试真题2025
- 平面设计渐变课件
- 平面设计x展架课件
- 平面构成中的骨骼课件
- 排污许可证管理条例课件
- 乡镇人大主席“干在实处、走在前列”学习讨论发言材料
- 2025年食品安全管理员考试题库及参考答案
- 用户反馈收集及问题分析表
- 无人机飞行操作规范手册
- 【里斯】年轻一代新能源汽车消费洞察与预测 -新物种 新理念 新趋势(2024-2025)
- 医院收费室培训课件
- 信仰思政课件
- 重点小学小学语文毕业总复习小升初资料大全
- 产品测试管理办法
- 高原健康培训课件
评论
0/150
提交评论