Q:

Counting sentences, only sentences ending with punctuation + 2 spaces

I'm trying to figure out how to make a sentence counter, which I have, but the thing is, I need it to count a sentence ONLY when two spaces come after the period/question mark/etc. 
For example, with the code I have, if you enter the string "hello, my name is ryan..." it returns the count of 3 sentences. I need it to only count one sentence.
This program needs to count words also. I count the words by taking the amount of spaces - 1. This is where my problem lies, I either mess up the word count or the sentence count. 
Here is the method for the word count:
public static int countWords(String str){
     if(str == null || str.isEmpty())
        return 0;

     int count = 0;
     for(int i = 0; i < str.length(); i++){
        if(str.charAt(i) != ' '){
           count++;
           while(str.charAt(i) != ' ' && i < str.length()-1){
              i++;
           }
        }
     }
     return count;
  }

And here is the method for counting sentences:
public static int sentenceCount(String str) {
     String SENTENCE_ENDERS = ".?!";

     int sentenceCount=0;
     int lastIndex=0; 
     for(int i=0;i < str.length(); i++){  
        for(int j=0;j < SENTENCE_ENDERS.length(); j++){  
           if(str.charAt(i) == SENTENCE_ENDERS.charAt(j)){
              if(lastIndex != i-1){
                 sentenceCount++;
              }
              lastIndex = i;
           }
        }

     }
     return sentenceCount;
  }

A:

I actually got it, using regex, was super simple also.
public static int sentenceCount(String str) {

  String regex = "[?|!|.]+[ ]+[ ]";
  Pattern p = Pattern.compile(regex);
  int count = 0;
  Matcher m = p.matcher(str);       
  while (m.find()) {
     count++;
  }
  if (count == 0){
     return 1;
  }
  else {
     return count + 1;
  }
  }  

Works great, I added the if statement assuming user is inputting at least one sentence, and added one to the count assuming they won't put two spaces at the end of their last sentence.

