You are on page 1of 1

//transmiddle.

java
import javax.swing.JOptionPane;
public class transmiddle {

public static void main(String args[]) {


String sentence,word=" ",newsent=" ";
char x=' ',y=' ';
int index=0,nofchar=0,wordlen=0;

sentence=JOptionPane.showInputDialog("Enter a sentence: ");


nofchar=sentence.length();

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 ";
}}

JOptionPane.showMessageDialog(null,newsent,"BY:Charles and Ronnie", JOptionPane.INFORMATION_MESSAGE);


System.exit(0);

You might also like