Thunderbird
Newcomer
So I'm working on an assignment where I need to create a counter class that can compute the number of sentences in a paragraph. The paragraph is just some little thing like, " This is a sentence. This is too."
The point is to learn about while loops with if statements in them. Here's what I have so far:
public class Counter {
public Counter (String paragraph ){
s1 = paragraph;
}
public String getSentenceCount(){
int i = 0;
int sentence = 0;
while ( i < s1.length())
if (s1.charAt(i) .equals(".") || s1.charAt(i) .equals("!") || s1.charAt(i) .equals("?"))
sentence ++;
i ++;
return s1;
}
private String s1;
}
The error that I get three times is this, " line 13: char cannot be dereferenced" reffering to my i variable each time in the if statement. Can anyone clue me in?
The point is to learn about while loops with if statements in them. Here's what I have so far:
public class Counter {
public Counter (String paragraph ){
s1 = paragraph;
}
public String getSentenceCount(){
int i = 0;
int sentence = 0;
while ( i < s1.length())
if (s1.charAt(i) .equals(".") || s1.charAt(i) .equals("!") || s1.charAt(i) .equals("?"))
sentence ++;
i ++;
return s1;
}
private String s1;
}
The error that I get three times is this, " line 13: char cannot be dereferenced" reffering to my i variable each time in the if statement. Can anyone clue me in?