Recently saw a netizen of a small problem, about the string segmentation, think about, and then give the code, and encountered a Java string to determine the end of the problem, and c\c++ with "" "to determine the end of the string is different, Java string is a class object, that is, the strings class object, There is no question of how much is given. Just enclose them in double quotation marks. For example: String str = "ABC"; String str2 = "DDD"; Then STR+STR2 is "abcddd." /** A small exercise in string segmentation* such as str = "11223444"; divided into 11,22,3,444 output */String str ="11222333334456666" ;
for(
inti=0; I<str.length ();) {
intj=i;
intnum=0;
while(Str.charat (j) ==str.charat (j+1)) {num++;j + +;
if((j+1) ==str.length ())//If the j+1 is out of bounds, an exception is thrown when the while loop is being judged
Break; }num++;String strout = str.substring (i, i+num);System.
out. println (strout);i = i+num; }
A little exercise in Java string splitting