77范文网 - 专业文章范例文档资料分享平台

第六次实验

来源:网络收集 时间:2019-03-09 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库第六次实验在线全文阅读。

第六次实验.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/502186.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: