Given a string.Replace the words whose length>=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

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package XXXXX;

import java.util.StringTokenizer;

/**
*
* @author poochedi
*/
public class SplitStringHalves {

public static void main(String[] args) {

String input = “Hello How are youu eleven’s heartt”;
String output = “”;
StringTokenizer st = new StringTokenizer(input);
while(st.hasMoreTokens()) {

String string = st.nextToken();
if(string.length() >=4 && string.length()%2 == 0) {

System.out.println(“String qualified ” + string);
int spaceAfter = string.length() / 2; //determine space after how many chars
System.out.println(“Space needed ” + spaceAfter);
String stringPartA = string.substring(0,string.length()/2);
if(stringPartA.length() == spaceAfter)
stringPartA+=” “;
String stringPartB = string.substring(string.length()/2, string.length());
string = stringPartA + stringPartB;
System.out.println(“String ” + string);
}

output+=” ” + string;
}
System.out.println(“Input ” + input);
System.out.println(“Output ” + output);
}

}

Advertisements