Reputation: 355
Console prints illegal start of expression. Method is for finding letters in input String. Is it different when the method is under main or above it? Could netBeans cause the issue?
package wars;
public class Wars {
static String printerError(String s) {
int a = 0;
for (int i = 0; i < s.length(); i++) {
if (!s.substring(i, i + 1).equals("a")
|| !s.substring(i, i + 1).equals("b")
|| !s.substring(i, i + 1).equals("c")
|| !s.substring(i, i + 1).equals("d")
|| !s.substring(i, i + 1).equals("e")
|| !s.substring(i, i + 1).equals("f")
|| !s.substring(i, i + 1).equals("g")
|| !s.substring(i, i + 1).equals("h")
|| !s.substring(i, i + 1).equals("i")
|| !s.substring(i, i + 1).equals("j")
|| !s.substring(i, i + 1).equals("k")
|| !s.substring(i, i + 1).equals("l")
|| !s.substring(i, i + 1).equals("m")) {
a++;
}
}
return a + "/" + s.length();
}
public static void main(String[] args) {
System.out.println(Wars.printerError("pokemon"));
}
}
Upvotes: 0
Views: 80
Reputation: 105
Your code seems to be working for me without any errors.
You aren't printing the returned value. Add the following line to the main method.
System.out.println(printerError("pokemon"));
Upvotes: 1
Reputation: 181
There is no difference. If you want to know the result, you might want to modify the code as shown below.
public static void main(String[] args) {
System.out.println(printerError("pokemon"));
}
Upvotes: 2