日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

20175305张天钰《java程序设计》第七周学习总结

發布時間:2025/3/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 20175305张天钰《java程序设计》第七周学习总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

《java程序設計》第七周學習總結


第八章 常用實用類

1.String類

1.String類不可以有子類。
2.用戶無法輸出String對象的引用,輸出的是字符序列
3.構造方法:String s = new String("We are students");
4.其他構造方法:String (char a[ ]) 和 String(char a[],int startIndex,int count)

2.字符串的并置

*1.String對象可以用“+”進行并置運算,即首尾相接得到一個新的String對象。

3.String類的常用方法

1.public int length( ) 用來獲取一個String對象的字符序列的長度;
2.public boolean equals(String s) 用來比較當前String對象的字符序列是否與參數s指定的String對象的字符序列相同;
3.public boolean startsWith(String s)、public boolean endsWith(Sting s) 判斷當前String對象的字符序列前綴是否是參數指定的String對象s的字符序列;
4.public boolean contains(String s) 用來判斷當前String對象的字符序列是否包含參數s的字符序列;
5.public int indexOf (string s) 從當前String對象的字符序列的0索引位置開始檢索首次出現s的字符序列位置并返回該位置,若沒檢索到,該方法的返回值為-1;
6.public int lastIndexOf(String s) 從當前String對象的字符序列的0索引位置開始檢索最后一次出現s的字符序列的位置,并返回該位置,若沒檢索到,則返回-1;
*7.public String trim() 得到一個新的String對象,這個String對象的字符序列是當前String對象的字符序列去掉前后空格后的字符序列。

4.字符串與字符、字節數組

1.字符串與字符數組的方法:getChars//復制到參數c指定的數組中和public char[] toCharArray()
2.字符串與字節數組的方法:
String(byte[],int offset,int length)
public byte[] getBytes()
public byte[] getBytes(String charsetName)
*3.字符串的加密算法:P186

5.正則表達式:

*正則表達式是一個String對象的字符序列,該字符序列中含有具有特殊意義的字符,這些特殊字符稱作正則表達式的元字符

元字符:

6.常用使用類

1)StringTokenizer類

1.StringTokenizer(String s)
2.StringTokenizer(String s, String delim)

2)Scanner類

1.next()方法用來一次返回被解析的字符序列中的單詞
2.如果含有數字可以用nextInt()和nextDouble()來代替next()方法。

3)StringBuffer類

1.length():獲取實體中存放的字符序列的長度。
2.capacity():獲取當前實體的實際容量。
3.StringBuffer append(String s):將String對象s的字符序列追加到當前StringBuffer對象的字符序列中,并返回當前StringBuffer對象的引用。
4、public char charAt(int n)和public void setCharAt(int n,char ch):得到序列位置n上的字符和替換ch指定的字符。
5、StringBuffer insert(int index,String str):將參數str指定的字符序列插入到參數index指定的位置。
6、public StringBuffer reverse():將對象實體中的字符序列翻轉。
7、StringBuffer delete(int startIndex,int endIndex):從當前StringBuffer對象的字符序列中刪除一個子字符序列,并返回當前對象的引用。
8、StringBuffer replace(int startIndex,int endIndex,String str):將當前StringBuffer對象的字符序列的一個子字符序列用參數str指定的字符序列替換。

4)Date類與Calendar類

1.使用無參數構造方法:Date()
2.使用帶參數的構造方法:Date(long time)
3.使用Calendar類的static方法getInstance()可以初始化一個日歷對象:Calendar calendar = Calendar.getInstance()
Date date = new Date();
long dt=315532800;//十年前 單位是ms 1000ms=1s
date.setTime(System.currentTimeMillis()-dt1000);
/formate方法/
/* %ty 年 %tm 月 %td 日 /
/ %tY 4位年 */
System.out.println(String.format("%tY-%<tm-%<td",date));
System.out.println(String.format("%tm/%<td %<tY",date));
System.out.print(String.format(Locale.CHINA,"%tY年%<tm月%<td日 %<ta",date));

5)日期的格式化

1.format方法:format(格式化模式,日期列表)
2.format(Locale locale,格式化模式,日期列表);

6)Math類:用于靜態方法、常量E和PI

1.public static long abs(double a)
2.public static double max(double a,double b)
*3.public static double min(double a,double b)

7)BigInteger類:用于處理特別大的整數

1.public BigInteger add(BigInteger val)
2.public BigInteger subtract(BigInteger val)
*3.public BigInteger multiply(BigInteger val)

8)Random類:用于產生隨機數

7.托管代碼

public static void main(String []args){
String mess="姓名:張三 出生時間:1989.10.16.個人網站:http://www.zhang.com 身高:185cm,體重:72kg";
int index= mess.indexOf(":"); //返回字符串中首次出現冒號的位置
String name=mess.substring(index+1);
if(name.startsWith("張")) System.out.println("簡歷中的姓名姓張");
index= mess.indexOf(":",index+1); //返回字符串中第2次出現冒號的位置
String date=mess.substring(index+1,index+11);
System.out.println(date);
index=mess.indexOf(":",index+1);
int heightPosition= mess.indexOf("身",index+1);//返回字符串中首次出現身高的位置
String personNet=mess.substring(index+1,heightPosition-1);
System.out.println(personNet);
index=mess.indexOf(":",heightPosition);//返回字符串中身高后面的冒號位置
int cmposition=mess.indexOf("cm");
String height=mess.substring(index+1,cmposition);
height=height.trim();
int h=Integer.parseInt(height);
if(h>=180){
System.out.println("簡歷中的身高"+height+"大于或等于180cm");
}
else {
System.out.println("簡歷中的身高"+height+"小于180cm");
}
index=mess.lastIndexOf(":");//返回字符串中最后一個冒號的位置
int kgPosition=mess.indexOf("kg");//轉化為整形
String weight=mess.substring(index+1,kgPosition);
weight=weight.trim();
int w=Integer.parseInt(weight);
if(w>=75){
System.out.println("簡歷中的體重"+weight+"大于或等于75kg");
}
else{
System.out.println("簡歷中的體重"+weight+"小于75kg");
}
}

總結:本章所學的常用實用類感覺非常有用,使得java編程更加快捷方便,并且可以理解很多代碼并學習

轉載于:https://www.cnblogs.com/zhangtianyu/p/10707612.html

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的20175305张天钰《java程序设计》第七周学习总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。