Professional Documents
Culture Documents
java
import javax.swing.JOptionPane;
public class transmiddle {
while(index<nofchar)
{while(index<nofchar&&sentence.charAt(index)==' ')
{
index++;
word=" ";
}
while(index<nofchar&&sentence.charAt(index)!=' ')
{
word+=sentence.charAt(index);
index++;
}
int a=word.length();
wordlen=a;
//odd or even
if((wordlen % 2)==0){
int i=wordlen/2;
x=word.charAt(i);
newsent+=x+word.substring(1,wordlen-i);
newsent+=word.substring(1+i,wordlen)+"AVA ";
}
else{
int i=wordlen/2;
y=word.charAt(i);
newsent+=y+word.substring(1,wordlen/2);
newsent+=word.substring(1+i,wordlen)+"AVA ";
}}