Given a string.Replace the words whose lengt>=4 and is even,with a space between the two equal halves of the word.consider only alphabets for finding the eveness of the word
I/P "A person can't walk in this street"
O/P "A per son ca n't wa lk in th is stre et"
static String stringReplace(String str)
{
String regex = " ";
String str1;
String str2;
StringBuilder builder = new StringBuilder();
String[] parts = str.split(regex);
for(int i=0; i <>= 4 && parts[i].length()%2==0)
{
str1 = parts[i].substring(0, parts[i].length()/2);
str2 = parts[i].substring(parts[i].length()/2,parts[i].length());
builder.append(str1);
builder.append(" ");
builder.append(str2);
}
else
builder.append(parts[i]);
if (i <> builder.append(" ");
}
return builder.toString();
}
}
Given a string.Replace the words
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment