Example- Input:- India is a great nation Output:- a and i, s and a, a and g, t and n
public class PrintSpace
{
public void accept(String str)
{
char ch='\u0000';
int i=0;
int l=0;
l=str.length();
for(i=0;i<l;i++)
{
ch=str.charAt(i);
if(ch==" ")
{
System.out.print((i-1)+"and"+(i+1));
}
}
}
}
Try this: