第六次实验
更新时间:2024-07-06 20:39:01 阅读量: 综合文库 文档下载
实实验验66 常常用用基基础础类类库库与与工工具具类类((11))
6.1、实验目的
? 掌握java常用的基础类库,如String的使用
6.2、实验准备
(1) JDK安装 (2) Eclipse的安装 (3) 书本第8章节的复习
6.3、实验内容与要求
1、使用类String类的分割split 将字符串 “Solutions to selected exercises can be found in the electronic document The Thinking in Java Annotated Solution Guide, available for a small fee from BruceEckel” 单词提取输出。单词以空格或,分割。
2、设计一个类Student,类的属性有:姓名,学号,出生日期,性别,所在系等。并生成学生类对象数组。按照学生的姓名将学生排序输出。使用String类的compareTo方法。
3、设计一个程序计算2010-05-01日与系统当前日期相差的天数。
§§11..22实实验验题题目目
1、 使用类String类的分割split 将字符串 “Solutions to selected exercises can be found in the electronic document The Thinking in Java Annotated Solution Guide, available for a small fee from BruceEckel” 单词提取输出。单词以空格或,分割。 参照课本P10 例2.5 运行代码: package EX1_1;
public class EX1_1 {
public static void main(String[] args) {
String str1=new String(\
electronic document The Thinking in Java Annotated Solution Guide,available for a small fee from BruceEckel\ }
String[] str2=str1.split(\for(int i=0;i System.out.println(str2[i]); } 运行截图: 2、 调试p14 例2.8,将程序加上注释。 运行代码: package EX1_2; public class EX1_2 { public static void stringRepalce(String text){ } public static void bufferRepalce(StringBuffer text){ text=text.append(\把 Object 型参数的字符串表示添加到该字text=text.replace('j','i');//替换函数 把j替换成i 符串缓冲区 } public static void main(String[] args) { }} String ts=new String(\字符型 StringBuffer tb=new StringBuffer(\型 stringRepalce(ts);//调用函数 bufferRepalce(tb); System.out.println(ts+\打印输出 运行截图: stringRepalce函数中传进来的只是形参,是对原值的拷贝,原值不改变。bufferRepalce函数是对字符串缓冲区进行修改,是对原值的修改,故发生改变。 3、 调试p15 例2.10,将程序加上注释。 运行代码: package EX1_3; import java.text.SimpleDateFormat; import java.util.Date; public class EX1_3 { public static void main(String[] args) { SimpleDateFormat format1=new SimpleDateFormat(\年MM月dd 日HH时mm分ss秒\指定格式输出 SimpleDateFormat format2=new SimpleDateFormat(\ SimpleDateFormat format3=new SimpleDateFormat(\ HH:mm:ss\ SimpleDateFormat format4=new SimpleDateFormat(\年MM月dd日 HH时mm分ss秒 E\ } 运行截图: 4、 设计一个程序计算2010-05-01日与系统当前日期相差的天数。 参照题3与书本上P17完成。 运行代码: package EX1_4; import java.util.Date; import java.text.ParseException; } Date date=new Date(); System.out.println(format1.format(date));//格式化输出 System.out.println(format2.format(date)); System.out.println(format3.format(date)); System.out.println(format4.format(date)); System.out.println(date.toString());//默认输出格式 import java.text.SimpleDateFormat; public class EX1_4 { public static void main(String[] args) { } } 运行截图: 5、 设计一个类Student,类的属性有:姓名,学号,出生日期,性别,所在系等。并生成学生类对象数组。按照学生的姓名将学生排序输出。使用String类的compareTo方法。 1)、定义学生类 class Student{ String input = \ SimpleDateFormat formatter = new SimpleDateFormat(\ Date d1 = null; Date d2 = new Date(); try { d1= formatter.parse(input); } catch (ParseException e) { } long diff = d2.getTime() - d1.getTime(); System.out.println(\ e.printStackTrace(); private String sno,sname,sbirth,ssex,sdept;//构造函数,set-get函数 } 2)、创建一个测试类 public class Ex1_2{ public Student[] initStudent(){ //初始化学生信息 Student s[]=new Student[5]; String[] names={\ ...//定义几个数组放置属性信息 for(int i=0;i s[i]=new Student(nos[i],names[i],births[i],sess[i],depts[i]); return s; } public void sortStudent(Student[] s){//排序按照姓名,选择法 for(int i=0;i for(int j=i+1;j if((s[min].getSname().compareTo(s[j].getSname())>0) min=j; if(min!=i){ Student t=s[i];s[i]=s[min];s[min]=t; } } } public void dispStudent((Student[] s){//输出学生信息 .. } public static void main(String[] args){ Ex1_2 obj=new Ex1_2(); Student[] s=obj.initStudent(); obj.sortStudent(s); obj.dispStudent(s); } } 运行代码: package EX1_5; public class Student { private String sno,sname,sbirth,ssex,sdept; Student(String sno,String sname,String sbirth,String ssex,String sdept){ } public String getSno() { this.sno=sno; this.sname=sname; this.sbirth=sbirth; this.ssex=ssex; this.sdept=sdept; } return sno; public void setSno(String sno) { } public String getSname() { } public void setSname(String sname) { } public String getSbirth() { } public void setSbirth(String sbirth) { } public String getSsex() { } public void setSsex(String ssex) { } public String getSdept() { this.ssex = ssex; return ssex; this.sbirth = sbirth; return sbirth; this.sname = sname; return sname; this.sno = sno; } } return sdept; public void setSdept(String sdept) { } this.sdept = sdept; package EX1_5; public class Test { public Student[] initStudent(){ //初始化学生信息 Student s[]=new Student[5]; String[] snos={\ String[] names={\}; String[] births={\ String[] sess={\男\男\男\女\男\ String[] depts={\计算机\数学\英语\测控\经济\ for(int i=0;i s[i]=new Student(snos[i],names[i],births[i],sess[i],depts[i]); return s; public void actionPerformed(ActionEvent e) { } public static void main(String[] args) { } } 运行截图: String str1=jb_year.getSelectedItem().toString(); String str2=jb_mon.getSelectedItem().toString(); if(str1.equals(\ table.setModel(new DefaultTableModel(rows,cols)); else{ } int year=Integer.parseInt(str1); int mon=Integer.parseInt(str2); showCalendar(year,mon); JFrame.setDefaultLookAndFeelDecorated(true); EX1_6 test=new EX1_6(); test.setVisible(true);
正在阅读:
第六次实验07-06
软件工程考试题(带答案)01-14
上海市静安区2015届高三上学期期末(一模)质量检测物05-21
第三章 热力学第二定律04-10
实习生三个月试用期个人工作总结范文02-26
这一次,赵本山能挺过去吗?05-21
大家的日本语15课08-20
- 清真菜谱
- 我国国民经济和社会发展十二五规划纲要(全文)
- 高三物理机械振动和机械波复习2
- 浙江省公路山岭隧道机械化装备应用指导手册 doc - 图文
- 2018届高三数学文科二轮复习:专题检测(九) 导数的简单应用
- 2015年上海市公务员录用考试《行政职业能力测验》试卷(B类)
- 七年级道德与法制下册
- 大班户外游戏教案
- 病虫害预警 - 图文
- 某养鱼场为了提高经营管理水平
- 汉中市勉县尧柏余热汽机规程 10
- 烹饪试卷
- 事业单位考试公共基础知识专项分类题库训练
- 语文:第2课 走一步,再走一步 课堂导学案(人教版 七上)
- 天汉使用手册
- 人教版小学三年级数学下册教学计划
- 房地产销售管理完全操作手册122页
- 2009年评审通过具有中学高级教师专业技术资格人员名单...
- 《15秋公共关系学》作业1
- 2017最新版监理公司三标一体管理手册
- 实验
- 最新人教版小学五年级下册体育教案全集
- 事业单位岗位工资薪级工资标准及套改表 - 图文
- 执业医师考试-内科学-题库(含备注解释)
- 七年级英语下册Unit6 Topic2同步练习2 最新仁爱版
- 南京林业大学思修题库
- 2014年北京高考数学(文科)试题及答案
- 2016-2022年中国装甲门行业分析及市场前景预测报告
- 实验一 顺序表操作实现
- 2016国际博物馆日活动总结
- 让农村资源在幼儿日常生活中有效利用
- 示范智能车间申请报告
- 河南大学继续教育学院报名学费
- XML基础及实践开发教程(唐琳 主编)习题答案
- 浙美版小学美术 3.大学之门 教学设计
- 河南师范大学函授报名
- 液位开关项目可行性研究报告
- 2013-2014学年高一地理人教版必修二导学案 3.2 以种植业为主的农
- 河南工业大学成人函授招生专业
- 论网络流行语对大学生人际关系的影响及对策分析-最新教育资料
- 一级应用基础 模拟考试选择题