\*

```
import java.util.*;
class Word{
  void main(){
    char ch='\u0000',firstc,lastc;
    int c=0,lw; String w="",s1="";
    Scanner in = new Scanner(System.in);
    System.out.println("Enter a String");
    String n = in.nextLine();n=n+"";
    for (int i=0;i<n.length();i++){
      ch = n.charAt(i);
      if(ch!=' '){
        w=w+ch;
      }else{
        firstc = w.charAt(0);
        lastc = w.charAt(w.length()-1);
        if(firstc==(lastc))
        s1=s1+w;
        System.out.println(""+s1);
      }
    }
    w=" ";
  }
}

```

\*
Now the output comes for one string like if I give MADAM HAVE A MODEM as input it only gives me MADAM as output.