实验六 字符串处理及基础类库.doc_第1页
实验六 字符串处理及基础类库.doc_第2页
实验六 字符串处理及基础类库.doc_第3页
实验六 字符串处理及基础类库.doc_第4页
实验六 字符串处理及基础类库.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验六 字符串处理及基础类库一、实验目的1、 理解并掌握String类、StringBuffer类; 2、 理解并掌握StringTokenizer类3、 掌握字符串与其他数据类型的转换4、 掌握Math类的使用。5、 了解和掌握集合框架类。6、 掌握Java Application命令行参数的使用 二、实验内容与要求1,理解String类的使用利用下面的关键代码编写一个完整的程序String s=new String(This is an demo of the String method.);/String s=This is an demo of the String method.;System.out.println(Length: +s.length();System.out.println(SubString: +s.substring(11,15); public class theString public static void main(String args)String s=new String(This is an demo of the String method.);/String s=This is an demo of the String method.;System.out.println(Length: +s.length(); System.out.println(SubString(int):+s.substring(11);System.out.println(SubString(int, int): +s.substring(11,15); 2理解StringBuffer类的使用利用下面的关键代码编写一个完整的程序StringBuffer sb=new StringBuffer(Hello World!);sb.append( Hello Java!);sb.insert(12, And);System.out.println(sb);System.out.println(sb.charAt(0);sb.setCharAt(0,h);System.out.println(sb.charAt(0);System.out.println(sb);public class theStringBuffer public static void main(String args)StringBuffer sb=new StringBuffer(Hello World!);sb.append( Hello Java!);sb.insert(12, And);System.out.println(sb);System.out.println(sb.charAt(0);sb.setCharAt(0,h);System.out.println(sb.charAt(0);System.out.println(sb);3理解集合泛型的使用1、编写程序练习List集合的基本使用:1) 创建一个只能容纳String对象名为names的ArrayList集合;2)按顺序往集合中添加5个字符串对象:“张三”、“李四”、“王五”、“马六”、“赵七”;3)对集合进行遍历,分别打印集合中的每个元素的位置与内容;4)首先打印集合的大小,然后删除集合中的第3个元素,并显示删除元素的内容,然后再打印目前集合中第3个元素的内容,并再次打印集合的大小。import java.util.ArrayList;public class theArrayList public static void main(String args) ArrayList names = new ArrayList();names.add(张三 );names.add(李四);names.add(王五);names.add(马六);names.add(赵七);for(int i = 0; i”1”、name”张三”、sex”男”、age”25”、love”爱学Java”3)对集合进行遍历,分别打印集合中的每个元素的键与值;4)首先打印集合的大小,然后删除集合中的键为age的元素,并显示删除元素的内容,并再次打印集合的大小。、import java.util.HashMap;public class theMap public static void main(String args) HashMap person = new HashMap();person.put(id, 1);person.put(name, 张三);person.put(sex, 男);person.put(age, 25);person.put(love, 爱学 Java);System.out.println(id + person.get(id);System.out.println(name + person.get(name);System.out.println(sex + person.get(sex);System.out.println(age + person.get(age);System.out.println(love + person.get(love);System.out.println(集合的大小为: + person.size();System.out.println(删除集合中的键为age的元素: + person.get(age);person.remove(age);System.out.println(删除后元素集合为:);System.out.println(id + person.get(id);System.out.println(name + person.get(name);System.out.println(sex + person.get(sex);/System.out.println(age + person.get(age);System.out.println(love + person.get(love);System.out.println(删除后集合的大小为: + person.size();4理解Math类的使用利用下面的关键代码编写一个完整的程序System.out.println (Math.abs (-5.8); /5.8System.out.println (Math.ceil (3.2); /4System.out.println (Math.floor (3.8) /3System.out.println (Math.round (3.8); /4System.out.println (Math.round (3.2); /3System.out.println (Math.min (3,2); /2System.out.println (Math.max (Math.PI,4); /4System.out.println (Math.log (7.0); /1.94591System.out.println (Math.pow (7,2); /72 - 49System.out.println (Math.exp (0.4); /1.49183System.out.println (Math.IEEEremainder(10.0,3.0); /返回1angle = 0.785398; /以弧度为单位的角,/4System.out.println (Math.tan (angle); /返回该角的正切System.out.println (Math.asin(0.707107); /返回反余弦System.out.println (e is:+ Math.e); / e is:2.71828System.out.println (is:+Math.PI); /is:3.14159System.out.println(Math.random(); /产生0和1(不含1)之间的伪随机数public class theMaths public static void main(String args)System.out.println (对-5.8取绝对值是:+Math.abs (-5.8); /5.8System.out.println (对3.2返回最小(最接近负无穷大)浮点值,该值大于等于该参数,并等于某个整数:+Math.ceil (3.2); /4System.out.println (对3.8返回最大的(最接近正无穷大)double 值,该值小于等于参数,并等于某个整数:+Math.floor (3.8); /3System.out.println (对3.8返回最接近参数的 long:+Math.round (3.8); /4System.out.println (对3.2返回最接近参数的 long:+Math.round (3.2); /3System.out.println (返回两个 int 值中较小的一个:+Math.min (3,2); /2System.out.println (返回a和b的较大值:+Math.max (Math.PI,4); /4System.out.println (返回 double 值的自然对数(底数是 e):+Math.log (7.0); /1.94591System.out.println (返回7的2次幂的值:+Math.pow (7,2); /72 - 49System.out.println (返回欧拉数 0.4的 double 次幂的值:+Math.exp (0.4); /1.49183System.out.println (按照 IEEE 754 标准的规定,对参数10.0、3.0进行余数运算:+Math.IEEEremainder(10.0,3.0); /返回1double angle = 0.785398; /以弧度为单位的角,/4System.out.println (返回角的三角angle的正切:+Math.tan (angle); /返回该角的正切System.out.println (返回0.707107的反正弦:+Math.asin(0.707107); /返回反余

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论