如果您使用类似的方法,它将起作用:
if (raw.charAt(3) == '-' && raw.charAt(7) == '-') { System.out.println("2 Hyphens at 3 and 7"); } else if (raw.charAt(3) == '-' && raw.charAt(8) == '-') { System.out.println("2 Hyphens at 3 and 8"); } else if (raw.charAt(3) == '-' && raw.charAt(9) == '-') { System.out.println("2 Hyphens at 3 and 9"); }问题是
raw.charAt(n)返回a
char而不是a
String。该
equals()方法只能用于对象。Char是没有方法的原始数据类型。在char上,您应该使用
==或运算符
!=。



