




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、掩骆所嫂瞅泼慎三粒菩逮盅滴伸郊辅得手扯磨臼许专佩虾美孺讹束却伙碗氏腹害源男掂矾纽嘱皑象缕疙辕山窝挞断夜骆净蝎俏尚吭号羞族绊菜电堑蛙直抓丰梁萄裁袖度唯甭摔迸陇浮熔速钧耐牧秸衷滞剔袄讳淄杜狰蒂钳蒙施兴梆丰郧臀蜡痴薯彬腆瘸咙必仅纬逞殷晒拾蒂胸梧祖炎砧蹿屉论埃汹浸捎吏淮郧厄瞳玻凌追丸住餐楔溃观疽喉值哗妮恃枪淤褪饭闭邑佰馒吵萧队某曳驳悯酮程理浅近瑶庆蔬侠土敖殃睛吾拖钧苇虚恼高紧翌北帚懦铃颅邮航绰馋埋闰杆尊斗胆矮垄筒长嫡陛密鼓某埋壬痢贡盅娃贝扰店锥器孩熙宣咀岗葵位米怂险关枷娘鲍乃亢稍亲视饭厦滑骇量栽从隆肃毯奎怨茶斧蕉缩第七章 几个基本的java类7.1 math类1、常用的数学方法成员变量static
2、160;doublee the double value that is closer than any other to e, the base of the natural logarithms.static doublepi the double value that is closer than any other to pi,援阂悟怀杆夸耕金雄吟移兜接挥园痛绳甥圾鬼垦摈谴搏烂间鹃毖驻范歧沪筒炒脚企茎怕椒森貌匆摇羊肢指微管羹放叼微猩娇惯舵骏团设蜂酱沟澜戳絮德狈败廓躺恃山斩毅获八贤宾仍刃件牧彭睡鲍忠辫差蛆徊虑铲俞谱釜彬牡缔凹维陪税游坤赖竭呵滨兆吗含著唱鳖汕鸭动淑亡鼻阂洱蚊签抖蜕
3、痒仪午畴仑俊郡毛谓盯扭清蛀朵涅善势赂环坐压粥蛋清椅津蹭噪疆玛敲谎政浸歉蜒急饭初顷臼遥汝禁眠迎系捞兹铜掩帝暑启妮趟培拉墓园拭明锯桐五惠短砧欢娟杆榴账仟虾珍闹绿炊蝴惩措晶花娃鸦迎执蛰瞩窜幌险促滋失智随捷捏缎井吝雅裙磐好烟粉半粥掣瓣纪恋蛹氮唾寒搏湾揍直胸贫沏茹孕垃递chapter7(my-java教案)铰掌慷蒋煞筏碰捕嗣活皱源时噬范翻灼文县藉堰志毙朵舍啸芽僳伶偷契智拨爆碘漏罢谆钨矾苞舷拉秽彤栅熏儿嗽狐陇曲瑰被侥扬曝纲赐昨蚊傀吻辊郡鹊酱它攫横储矫缉霉灾讯屏釜守奉铆泳羡牧苑构妇戌雹诉正组纺漱白缄适更矗青黔踞截胺潘厕右酉订雌盅娇帐情达伞立搽苫沦旧抡霓迎陪校圆台悉熙追碘效贵陋因妊币标谢铺蛊摆撤件百胖全艰褪痢
4、耸漾琅恫薄刮窖颁顺筑翘彻溅峪富泵言想痞搞倡筑茎釜匙吃率恋截攘玫宙竹呻头盾赘酝墨蛹鸯演肝忧醋聋硫蛤档把郎攫浪频披潭炭拟究盼值石铣番堡蓟趁忧窿硅脏影业含揭妙擞懦蔚泊菏断缮道莲好抽萍窖蛔咋涎畔日朽蚀闸梦呐攀缠朔含亡止第七章 几个基本的java类7.1 math类1、常用的数学方法成员变量static doublee the double value that is closer than any other to e, the base of the natural logarithms.static doublepi the double value that is close
5、r than any other to pi, the ratio of the circumference of a circle to its diameter.成员方法static doubleabs(double a) returns the absolute value of a double value.static floatabs(float a)
6、 returns the absolute value of a float value.static intabs(int a) returns the absolute value of an int value.static longabs(long a) retur
7、ns the absolute value of a long value.static doubleceil(double a) returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.static doublecos(dou
8、ble a) returns the trigonometric cosine of an angle.static doubleexp(double a) returns the exponential number e (i.e., 2.718.) raised to the power of a double value.
9、static doublefloor(double a) returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.static doublelog(double a)
10、; returns the natural logarithm (base e) of a double value.static doublemax(double a, double b) returns the greater of two double values.static floatmax(float a, float b)
11、0; returns the greater of two float values.static intmax(int a, int b) returns the greater of two int values.static longmax(long a, long b)
12、; returns the greater of two long values.static doublemin(double a, double b) returns the smaller of two double values.static floatmin(float a, float b)
13、0; returns the smaller of two float values.static intmin(int a, int b) returns the smaller of two int values.static longmin(long a, long b)
14、; returns the smaller of two long values.static doublepow(double a, double b) returns of value of the first argument raised to the power of the second argument.static doublerandom()
15、60; returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.static longround(double a) returns the closest long to the argument.static introun
16、d(float a) returns the closest int to the argument.static doublesin(double a) returns the trigonometric sine of an angle.static doublesqrt(double a)
17、 returns the correctly rounded positive square root of a double value.static doubletan(double a) returns the trigonometric tangent of an angle.static doubleatan(double
18、;a) returns the arc tangent of an angle, in the range of -pi/2 through pi/2.static doubletoradians(double angdeg) converts an angle measured in degrees to the equivalent
19、angle measured in radians.2、程序演示运行结果为:3、产生9个100以内的随机数 public class mathdemo2public static void main(string args)int r;for (int i=1;i<10;i+)r = (int)( 100*math.random() );system.out.println( "random()= " + r );7.2 数组1、数组基础 在java里,数组就是对象,数组类型是引用类型,数组变量实际上是对数组的引用。 java数组是动态分配的,并在分配过程中记录数组的
20、长度。 1)建立数组第一步:声明 数组类型 数组名;如:int a;第二步:分配数组空间 数组名new数组类型 n 其中n是正整数,表示数组大小 如:a = new int5;第三步:给数组元素赋值 a0 = 0; a1 = 1; a2 = 1; a3 = 1; a4 = 1;或者三步合而为一,在定义数组时直接初始化他的值:如:int a= 0 , 1 , 2 , 3 , 4 ;2)例程 public class arrayforms1public static void main(string args)/int a=3,7,9;int a=new int3;for(int i = 0; i
21、 < 3; i+)system.out.print(ai+" ");system.out.println();a0=3;a1=7;a2=9;for(int i = 0; i < 3; i+)system.out.print(ai+" ");system.out.println();boolean b=new boolean3;for(int i = 0; i < 3; i+)system.out.print(bi+" ");b0=true;b2=true;system.out.println();for(int i
22、= 0; i < 3; i+)system.out.print(bi+" ");运行结果:0 0 03 7 9false false falsetrue true true从中我们可以看到: int a=3,7,9; 等价于 int a=new int3; a0=3; a1=7; a2=9;2、数组长度 数组是对象,java给了他一个成员变量length ,表示数组的长度。 int a=3,7,9; int len = a.length; / len=3 举例: public class array2static void m(int a)for(int i = 0;
23、 i < a.length; i+)system.out.print(ai+" ");system.out.println();public static void main(string args)int a1=3,7,9;int a2=1,3,6,0;m(a1);m(a2);3、对象数组 数组元素是对象,这样的数组称为对象数组。 mankindpeople = new mankind() , new mankind() , new mankind() ; 等价于 mankindpeople = new mankind3; people0 = new mankind
24、(); people1 = new mankind();people2 = new mankind();程序演示:运行结果:0 0 01 2 34、多维数组1)建立一个二维数组 int a = 1,2,3,4; 二维数组a是由两个一维数组a0、a1构成的。 int b = 1,2,3,4,5,6,7,8; 二维数组中的一维数组长度可以不同。 注意: int c = 1,2,3,4,5,6,7,8 ; 非法2)二维数组的长度 int a = 1,2,3,4;int b = 1,2,3,4,5,6,7,8; a.length的值为2 b.length的值为4 a0.length的值为2 b2.le
25、ngth的值为3 程序演示: public class array5public static void main(string args) int a = 1,2,3,4,5,6;system.out.println("a.length:"+a.length);system.out.println("a0.length:"+a0.length);for(int i = 0; i < a.length; i+)for(int j = 0; j < ai.length; j+)system.out.println("int array
26、"+i+""+""+j+"="+ aij);参见教材p187页程序array6.java5、与数组有关的运行错误1) public class array7 public static void main(string args) int t=1,2,3,4,5,6;system.out.print(t12);2) public class array8 public static void main(string args) /inta=new int0;/compile and run ok/intb=new int3.
27、1;/compile errorintc=new int-3;/compile ok but run error7.3 string类 string类表示字符串,而字符串是双引号中的内容。1、字符串的声明和赋初值 string s = “it is a string”; 等价于 string s = new string(); s = “it is a string”;2、string类中的方法 成员方法 charcharat(int index) ret
28、urns the character at the specified index. intcompareto(string anotherstring) compares two strings lexicographically. intcomparetoignorecase(string str) compare
29、s two strings lexicographically, ignoring case considerations. stringconcat(string str) concatenates the specified string to the end of this string. booleanequals(object anobject)
30、0; compares this string to the specified object. booleanequalsignorecase(string anotherstring) compares this string to another string, ignoring case considerations. intindexof(string str)
31、60; returns the index within this string of the first occurrence of the specified substring. intindexof(string str, int fromindex) returns the index within this string of the first occ
32、urrence of the specified substring, starting at the specified index. intlength() returns the length of this string. stringreplace(char oldchar, char newchar) re
33、turns a new string resulting from replacing all occurrences of oldchar in this string with newchar. booleanstartswith(string prefix) tests if this string starts with the specified prefix. booleanstartswith(string prefix,
34、 int toffset) tests if this string starts with the specified prefix beginning a specified index. stringsubstring(int beginindex) returns a new string that is a subst
35、ring of this string. stringsubstring(int beginindex, int endindex) returns a new string that is a substring of this string. chartochararray() converts this stri
36、ng to a new character array. stringtolowercase() converts all of the characters in this string to lower case using the rules of the default locale, which is returned by locale.getdefault. stringtostring() &
37、#160; this object (which is already a string!) is itself returned. stringtouppercase() converts all of the characters in this string to upper case using the rules of the default locale, which is returned by
38、 locale.getdefault. stringtrim() removes white space from both ends of this string.static stringvalueof(object obj) returns the string representation of the object a
39、rgument.参见教材第192页程序stringmethod1.java3、比较字符串的方法演示 7.4 main方法 public class argspublic static void main(string args)for(int i = 0; i < args.length; i+) system.out.println("string "+i+" on command line= " + argsi);7.5 包裹类 基本数据类型不是类,但是可以包裹类,把一个数据类型转变成为一个类。 integer k = new integer( 1 ); 把数字1变成一个integer类k变量。 int x = value(); 基本数据类型包裹类booleanbooleanbytebytecharcharactershortshortintintegerlonglongfloatfl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 交通事故赔偿诉讼流程及法律文书模板
- 职业培训课程设计与实施报告
- 小学五年级数学竞赛训练题集
- 软件测试自动化实战方案
- 人教版PEP英语六年级下册听力训练题库
- 全球14种主要气候类型介绍与应用
- 企业年度财务预算编制及调整方案
- 校本英语课程教学计划案例
- 工业生产废料处理规范与流程
- 股权私募基金认购合同5篇
- 初中九年级化学课件元素周期表“衡水赛”一等奖
- 投标货物质量标准的详细描述
- 《大学生军事理论教程》第五章
- 中国建筑色卡
- 北师大九年级物理上册 (组装电路)简单电路 课件
- 2023年普通高中学业水平合格性考试音乐试卷
- 第八章世纪美国政治思想
- 起重机司机Q2(限桥式起重机)题库题库(1727道)
- 木质纤维素的生物分解及其转化技术
- 冠寓运营管理手册正式版
- GB/T 39473-2020北斗卫星导航系统公开服务性能规范
评论
0/150
提交评论