Reputation: 3
String word = JOptionPane.showInputDialog("Enter String");
for(int x = 0 ; x <= word.length() ; x++) {
for( ch = 'a' ; ch <= 'z' ; ch++) {
num++;
if(word.charAt[x].equalsIgnoreCase(ch)) {
int z += num;
num = 0;
}
}
}
Upvotes: 0
Views: 4955
Reputation: 13844
String#charAt() is a method and hence should be written as charAt(x)
not as charAt[x]
Upvotes: 1
Reputation: 691625
charAt
is a method. And method arguments are between parentheses, not brackets:
word.charAt(x)
It returns a char, which is a primitive type. And primitive types don't have methods. So word.charAt(x).equalsIgnoreCase(ch)
won't compile. If you want methods on Character, wrap the primitive type into a Character:
char c = word.charAt(x)
Character character = Character.valueOf(c);
...
Upvotes: 9
Reputation: 2900
charAt
is a method, not an array. Where you have square brackets, they must be round brackets. E.g.:
if(word.charAt(x).equalsIgnoreCase(ch)) {
Upvotes: 0