you are checking the space
variable length while printing the input values
check the input.length()
length instead of space.length
length that's why you are getting theStringIndexOutOfBoundsException
change this
here -> for (int i = 0;i<space.length;i++)
{
to this
for (int i = 0;i<input.length();i++)
{