What do apostrophes mean in java
in the book i'm learning from i came across this code snippit:
while (i < len) {
char c = s.charAt(i);
if (c == ’(’) {
count = count + 1;
} else if (c == ’)’) {
count = count - 1;
}
i = i + 1;
}
what do the apostrophes mean in (c == '(')
? also isn't there a syntax error here? it looks like (c == '(')
needs another开发者_JAVA技巧 ) at the end of it.
what about here : else if (c == ’)’)
?
They surround a char
in the same way that "
surround a string like String s = "a string"
.
In the code, it is testing if c
is a (
character.
(BTW, you have ’
characters in your code, and I think these should be '
characters.)
Single quotes indicate a character as opposed to a string which is wrapped in double quotes. So: char c = 'a'; string s = "a string";
Apostrophe here is used to surround one char value. With String you use "", with char you use ''
精彩评论