字符串abcde的子串個數(shù) 在java中怎樣比較字符串的長度?
在java中怎樣比較字符串的長度?使用string class的length()方法獲取字符串的長度,然后比較:public class example{public static void main
在java中怎樣比較字符串的長度?
使用string class的length()方法獲取字符串的長度,然后比較:public class example{public static void main(string[]args){string STR1=“ABCD”string STR2=“ABCDE”if(STR1)。長度()<str2。長度())系統(tǒng)輸出打?。ā陛^短的字符串是:”STR1)else系統(tǒng)輸出打印(“較長的字符串是:”STR2)}
public class string{public static void main(string argv)}{tstring S]={a”,”ab“,”ABC“,”ABCD“,”ABCDE“}for(int i=0I)&L.lengthi先生){ 結果=s[i].indexOf(“abc”) t系統(tǒng)輸出打?。ā鞍幼址瓵BC的字符串如下:”-t/t/result)}您一直在判斷s[0],更改int result=s[0]。Indexof(“ABC”)到int result=s[i]。索引(“ABC”)