Hi I keep getting this error whenever I try to input an empty String. Everything else so far works and if I put a space inside the String it works. I know this is really picky but I'm super curious what I should do in this situation to make sure it returns just an empty String.
**> HW2.nthWord(2,"")
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(Unknown Source)
    at HW2.nthWord(HW2.java:124)**
I did create a special instance for when this value is put in but it still does not work.
What do I need to to correct this?
/*nthWord takes an int and a String as input and returns a String:
The input int represents a number n that is assumed to be positive, and the output string 
contains every nth word of the input string, starting with the first word, separated by a single space.
 For this method, a word is defined to be a sequence of non-space characters.
There should be no space at the end of the output string.
*/
public static String nthWord( int number, String input ){
  StringBuilder create = new StringBuilder();
  int totalspaces = 0; //This is to hold a count of the number of spaces in a String
    if( number == 0){
    return input;
  }
  if(input == ""){
    return input;
  }
  else{
  for(int i = 0; input.charAt(i) != ' '; i = i + 1){
    create.append(input.charAt(i));
  }
  for( int i = 0; i < input.length() - 1 ; i = i + 1){
    if(input.charAt(i) == ' ' && i < input.length() - 1 && input.charAt(i+1) != ' '){
      if( i != input.length()-1 && input.charAt(i+1) != ' '){
        totalspaces = totalspaces + 1;
      }
      if(totalspaces % number == 0 && totalspaces != 0){
        create.append(' ');
        for(int j = i+1; input.charAt(j) != ' ' && j < input.length(); j = j+1){
          create.append(input.charAt(j));
          i = j;
        }
      }
    }
  }
    return create.toString();
  }
}
 
     
    