I am trying to make a program on word count which I have partially made and it is giving the correct result but the moment I enter space or more than one space in the string
public static int CountWords(String str){ if(str.length() == 0) return 0; int count =0; for(int i=0;i< str.length();i++){ if(str(i) == ' ') continue; if(i > 0 && str.charAt(i-1) == ' '){ count++; } else if(i==0 && str.charAt(i) != ' '){ count++; } } return count; }