Have you tried playing computer with a piece of paper and a pencil to see what that code does?
stringMatch("abc", "abc") → 2
stringMatch("abc", "abc") → 2 0 X
There are three kinds of actuaries: those who can count, and those who can't.
count=count++ is not correct
sai rama krishna wrote:I think it is safer to write
count=count+1;
even though it is little longer bug more bug proof code
No, one of them has already been shown to be incorrect.sai rama krishna wrote:. . . count += 1 or count=count++; . . .
That's a pleasureThank you all . . .
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Carey Brown wrote:"n = n + 1" says "I'm a noob". It tells the reader "STOP, and read this VERY carefully because it is not normal syntax". Slows down the process of reading lots of lines of code. (like we do here every day)
Use "n++". Don't fight it, get used to it, it's the way we do things.
There are three kinds of actuaries: those who can count, and those who can't.
That might give the same result but it is not a correct explanation. The correct explanation is to be found in the JLS (=Java® Language Specification) here.sai rama krishna wrote:Agree
count++ is post increment operator so always assign first to left hand side variable then increments. . . .
That JLS section wrote:The value of the postfix increment expression is the value of the variable before the new value is stored.
Piet Souris wrote:
Carey Brown wrote:"n = n + 1" says "I'm a noob". It tells the reader "STOP, and read this VERY carefully because it is not normal syntax". Slows down the process of reading lots of lines of code. (like we do here every day)
Use "n++". Don't fight it, get used to it, it's the way we do things.
Sorry, but that is nonsense.
a += b is shorthand for a = a + b, and a++ is shorthand for a += 1. If you want to live with shorthands, don't use java in the first place.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
I'm using Eclipse 2021-12 and it did not offer to include imports, static or otherwise.Piet Souris wrote:A java 8+ version of this:
Your IDE will do the static imports for you.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |