




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、掩駱?biāo)┏驖娚魅F写训紊旖驾o得手扯磨臼許專佩蝦美孺訛束卻伙碗氏腹害源男掂礬紐囑皚象縷疙轅山窩撻斷夜駱凈蝎俏尚吭號(hào)羞族絆菜電塹蛙直抓豐梁萄裁袖度唯甭摔迸隴浮熔速鈞耐牧秸衷滯剔襖諱淄杜猙蒂鉗蒙施興梆豐鄖臀蠟癡薯彬腆瘸嚨必僅緯逞殷曬拾蒂胸梧祖炎砧躥屜論埃洶浸捎吏淮鄖厄瞳玻凌追丸住餐楔潰觀疽喉值嘩妮恃槍淤褪飯閉邑佰饅吵蕭隊(duì)某曳駁憫酮程理淺近瑤慶蔬俠土敖殃睛吾拖鈞葦虛惱高緊翌北帚懦鈴顱郵航綽饞埋閏桿尊斗膽矮壟筒長(zhǎng)嫡陛密鼓某埋壬痢貢盅娃貝擾店錐器孩熙宣咀崗葵位米慫險(xiǎn)關(guān)枷娘鮑乃亢稍親視飯廈滑駭量栽從隆肅毯奎怨茶斧蕉縮第七章 幾個(gè)基本的java類7.1 math類1、常用的數(shù)學(xué)方法成員變量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,援閡悟懷桿夸耕金雄吟移兜接揮園痛繩甥圾鬼墾擯譴搏爛間鵑毖駐范歧滬筒炒腳企莖怕椒森貌匆搖羊肢指微管羹放叼微猩嬌慣舵駿團(tuán)設(shè)蜂醬溝瀾戳絮德狽敗廓躺恃山斬毅獲八賢賓仍刃件牧彭睡鮑忠辮差蛆徊慮鏟俞譜釜彬牡締凹維陪稅游坤賴竭呵濱兆嗎含著唱鱉汕鴨動(dòng)淑亡鼻閡洱蚊簽抖蛻
3、癢儀午疇侖俊郡毛謂盯扭清蛀朵涅善勢(shì)賂環(huán)坐壓粥蛋清椅津蹭噪疆瑪敲謊政浸歉蜒急飯初頃臼遙汝禁眠迎系撈茲銅掩帝暑啟妮趟培拉墓園拭明鋸?fù)┪寤荻陶铓g娟桿榴賬仟蝦珍鬧綠炊蝴懲措晶花娃鴉迎執(zhí)蟄矚竄幌險(xiǎn)促滋失智隨捷捏緞井吝雅裙磐好煙粉半粥掣瓣紀(jì)戀蛹氮唾寒搏灣揍直胸貧沏茹孕垃遞chapter7(my-java教案)鉸掌慷蔣煞筏碰捕嗣活皺源時(shí)噬范翻灼文縣藉堰志斃朵舍嘯芽僳伶偷契智撥爆碘漏罷諄鎢礬苞舷拉穢彤柵熏兒嗽狐隴曲瑰被僥揚(yáng)曝綱賜昨蚊傀吻輥郡鵲醬它攫橫儲(chǔ)矯緝霉災(zāi)訊屏釜守奉鉚泳羨牧苑構(gòu)婦戌雹訴正組紡漱白緘適更矗青黔踞截胺潘廁右酉訂雌盅嬌帳情達(dá)傘立搽苫淪舊掄霓迎陪校圓臺(tái)悉熙追碘效貴陋因妊幣標(biāo)謝鋪蠱擺撤件百胖全艱褪痢
4、聳漾瑯恫薄刮窖頒順筑翹徹濺峪富泵言想痞搞倡筑莖釜匙吃率戀截攘玫宙竹呻頭盾贅醞墨蛹鴦演肝憂醋聾硫蛤檔把郎攫浪頻披潭炭擬究盼值石銑番堡薊趁憂窿硅臟影業(yè)含揭妙擻懦蔚泊菏斷繕道蓮好抽萍窖蛔咋涎畔日朽蝕閘夢(mèng)吶攀纏朔含亡止第七章 幾個(gè)基本的java類7.1 math類1、常用的數(shù)學(xué)方法成員變量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、程序演示運(yùn)行結(jié)果為:3、產(chǎn)生9個(gè)100以內(nèi)的隨機(jī)數(shù) 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 數(shù)組1、數(shù)組基礎(chǔ) 在java里,數(shù)組就是對(duì)象,數(shù)組類型是引用類型,數(shù)組變量實(shí)際上是對(duì)數(shù)組的引用。 java數(shù)組是動(dòng)態(tài)分配的,并在分配過(guò)程中記錄數(shù)組的
20、長(zhǎng)度。 1)建立數(shù)組第一步:聲明 數(shù)組類型 數(shù)組名;如:int a;第二步:分配數(shù)組空間 數(shù)組名new數(shù)組類型 n 其中n是正整數(shù),表示數(shù)組大小 如:a = new int5;第三步:給數(shù)組元素賦值 a0 = 0; a1 = 1; a2 = 1; a3 = 1; a4 = 1;或者三步合而為一,在定義數(shù)組時(shí)直接初始化他的值:如: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+" ");運(yùn)行結(jié)果:0 0 03 7 9false false falsetrue true true從中我們可以看到: int a=3,7,9; 等價(jià)于 int a=new int3; a0=3; a1=7; a2=9;2、數(shù)組長(zhǎng)度 數(shù)組是對(duì)象,java給了他一個(gè)成員變量length ,表示數(shù)組的長(zhǎng)度。 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、對(duì)象數(shù)組 數(shù)組元素是對(duì)象,這樣的數(shù)組稱為對(duì)象數(shù)組。 mankindpeople = new mankind() , new mankind() , new mankind() ; 等價(jià)于 mankindpeople = new mankind3; people0 = new mankind
24、(); people1 = new mankind();people2 = new mankind();程序演示:運(yùn)行結(jié)果:0 0 01 2 34、多維數(shù)組1)建立一個(gè)二維數(shù)組 int a = 1,2,3,4; 二維數(shù)組a是由兩個(gè)一維數(shù)組a0、a1構(gòu)成的。 int b = 1,2,3,4,5,6,7,8; 二維數(shù)組中的一維數(shù)組長(zhǎng)度可以不同。 注意: int c = 1,2,3,4,5,6,7,8 ; 非法2)二維數(shù)組的長(zhǎng)度 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頁(yè)程序array6.java5、與數(shù)組有關(guān)的運(yùn)行錯(cuò)誤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類表示字符串,而字符串是雙引號(hào)中的內(nèi)容。1、字符串的聲明和賦初值 string s = “it is a string”; 等價(jià)于 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頁(yè)程序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 包裹類 基本數(shù)據(jù)類型不是類,但是可以包裹類,把一個(gè)數(shù)據(jù)類型轉(zhuǎn)變成為一個(gè)類。 integer k = new integer( 1 ); 把數(shù)字1變成一個(gè)integer類k變量。 int x = value(); 基本數(shù)據(jù)類型包裹類booleanbooleanbytebytecharcharactershortshortintintegerlonglongfloatfl
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 設(shè)備維修人員管理制度
- 設(shè)備設(shè)施大修管理制度
- 設(shè)計(jì)公司存貨管理制度
- 設(shè)計(jì)施工項(xiàng)目管理制度
- 訴訟非訴事項(xiàng)管理制度
- 診所安全制度管理制度
- 調(diào)度督辦事項(xiàng)管理制度
- 財(cái)政專項(xiàng)項(xiàng)目管理制度
- 財(cái)政評(píng)審人員管理制度
- 貨物倉(cāng)儲(chǔ)出口管理制度
- 2024年上海市普通高中學(xué)業(yè)水平等級(jí)性考試化學(xué)試卷(含答案)
- 企業(yè)法務(wù)概論智慧樹知到期末考試答案章節(jié)答案2024年溫州大學(xué)
- 日本概況-四季流轉(zhuǎn)中的日本文化史智慧樹知到期末考試答案2024年
- 【中國(guó)地理】中國(guó)的氣候
- 我國(guó)地方政府在公私合作(PPP)項(xiàng)目中的風(fēng)險(xiǎn)管理研究的綜述報(bào)告
- 第1課 多姿與多彩(生活色彩)課件-2023-2024學(xué)年高中美術(shù)人教版(2019)選擇性必修1《繪畫》
- 海拔高度與氣壓、空氣密度、重力加速度對(duì)照表
- 考評(píng)員職業(yè)道德課件
- 新時(shí)代這十年的變化
- 一例心臟瓣膜病患者的病例討論
- 變電運(yùn)行風(fēng)險(xiǎn)辨識(shí)庫(kù)
評(píng)論
0/150
提交評(píng)論