版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医务室领药工作制度
- 医疗合作办工作制度
- 医疗调委会工作制度
- 医院质控办工作制度
- 华测快检室工作制度
- 卫生室公卫工作制度
- 卫生院两纲工作制度
- 卫生院综治工作制度
- 危重症专科工作制度
- 县健教中心工作制度
- 3.3服务业区位因素及其变化课件高中地理人教版必修二2
- 【真题】2023年徐州市中考道德与法治试卷(含答案解析)
- 护患沟通与护患纠纷防范课件
- 孕妇的护理家庭护理
- 人教新课标五年级数学下册教材解读PPT
- 客服经理资质考前练习题库(327道)
- 产品五金外观检验标准
- 贵州事业单位考试事业单位考试模拟考试试卷(含答案)
- GB/T 16886.18-2022医疗器械生物学评价第18部分:风险管理过程中医疗器械材料的化学表征
- GB/T 1870-1995磷矿石和磷精矿中水分的测定重量法
- 民法学全套精美课件
评论
0/150
提交评论