Try splitting with Regular Expressions instead of using " " as delimiter:
Code:
String[] arr = input.split("\\s+");
     int length = arr.length;
That code will split String on any space character (space \n \r or \t) (if there is more characters in a row it will split only once).