【教学课件】第六章Java常用类.ppt





《【教学课件】第六章Java常用类.ppt》由会员分享,可在线阅读,更多相关《【教学课件】第六章Java常用类.ppt(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 第六章第六章 Java常用类常用类v日期时间类及数学类日期时间类及数学类v集合集合v向量类向量类v包装类包装类v 输入输出流类输入输出流类 字节流、字符流、一般文件字节流、字符流、一般文件1 6.1日期时间类和数学类日期时间类和数学类1.Date类类 日期时间类的父类日期时间类的父类Date()获取当前系统时间获取当前系统时间默认格式:默认格式:星期星期 月月日日时时分分秒秒计时标准计时标准年年常用方法常用方法:booleanafter(Datetime)booleanbefore(Datetime)Objectclone()intcompareTo(Datetime)Booleanequa
2、ls(Objectobj)lonegetTime()voidsetTime(lonetime)StringtoString()注意:年、月值的确定2 6.1时间类和数学类时间类和数学类2.Calendar类类抽象类,存于util包中 用于抽取日期、时间、星期的值,如:用于抽取日期、时间、星期的值,如:YEAR、MONTH、DATE、HOUR、MINUTE、SECOND 常见方法常见方法 intget(intfield)voidset(intfield,intvalue)DategetTime()voidsetTime(Datetime)GregorianCalendar类类Calendar类的
3、实例子类,用于公历形式的描述 用途:用途:利用日期时间完成操作(记录日志、打印、自动控制系统)33.GregorianCalendar类类 Calendar类的子类,实例类类的子类,实例类增加的方法增加的方法 voidadd(intfield,intvalue)booleanisLeapYear(intyear)4import java.util.*;class ch7_9 public static void main(String args)Date date1=new Date();Date date2=new Date();int sec_min=date2.getSeconds()-
4、date1.getSeconds();System.out.println(sec_min);long now=date1.getTime();System.out.println(now);(现在是:+date2.getYear()+年+date2.getMonth()+月+date2.getDay()+日+date2.getHours()+:+date2.getMinutes();date2.setTime(now);System.out.println(date1 的时间为:+date2.toString();54.数学类数学类Math 最终类 1)三角函数:三角函数:sin(doubl
5、ea)cos()tan()2)舍入函数:舍入函数:intround(floata)longround(doublea)/4舍5入intceil(doublea)/aintfloor(doublea)/=a?3)乘方函数:乘方函数:pow(doublex,doubley)exp(doublex)log(doublex)sqrt(doublex)4)其它函数:其它函数:abs(a)max(x,y)min(x,y)random()5)二个常数二个常数:double E、double PI 上述方法引用方式:上述方法引用方式:Math.方法方法();65.Random类类v专门处理随机数流的类,可产生
6、各种类型的随机数(布尔、浮点、整型以及高斯,配合随机数种子的设定,提取几率相同。在java.util包中1.构造方法构造方法Random()创建一个随机数生成器创建一个随机数生成器 Random(longseed)2.方法方法booleannextBoolean()voidnextBytes(byteb)结果存入数组中doublenextDouble()floatnextFloat()longnextLong()64位intnextInt(k)32位K指定生成结果的上限范围doublenextGaussian()平均值是 0.0,标准偏差是 1.0voidsetSeed(longseed)7i
7、mport java.util.*;public class rand public static void main(String dd)double df,sum=0;do df=Math.random();/System.out.println(df);sum+=df;while(sum=1);System.out.println(sum=+sum);Random R=new Random();int j=1;while(j=0&ch=a&ch=z)sb2.append(ch);k=Integer.parseInt(sb1.toString()*2;ss=sb2.toString();i
8、f(ss.equals(true)ff=Boolean.parseBoolean(ss);System.out.println(ff);/FF=Boolean.valueOf(sb2.toString();ff=FF.booleanValue();System.out.println(k*2*3.14f);23 向量包装类使用举例向量包装类使用举例*importjava.util.*;importjava.io.*;publicclassppt4_2Vectorv=newVector(1);Integeroi;main()ppt4_2obj=newppt4_2();obj.vec();void
9、vec()throwsIOExceptionintj;charmark=y;while(mark=y)j=0;while(j6)oi=newInteger(int)(Math.random()*100);v.addElement(oi);System.out.print(v.lastElement().toString()+”);j+;System.out.print(“continue(y/n):);mark=(char)System.in.read();System.in.skip(2);246.4输入输入/输出流类及文件的使用输出流类及文件的使用1.流概念的提出流概念的提出形象化的描述系
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 教学课件 教学 课件 第六 Java 常用

限制150内