第六次实验

2019-03-09 14:03

实实验验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());//默认输出格式


第六次实验.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:10大药害事件

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: