字符串abcde的子串个数 在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。长度())系统输出打印(”较短的字符串是:”STR1)else系统输出打印(“较长的字符串是:”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系统输出打印(“包含子字符串ABC的字符串如下:”-t/t/result)}您一直在判断s[0],更改int result=s[0]。Indexof(“ABC”)到int result=s[i]。索引(“ABC”)