Java expressions
This question already has an answer here:
what confuses you is that there is no whitespace between the T--
and the >
, so you might think there's a -->
operator.
looking like this:
while (T-- > 0) {
}
It makes more sense, in every loop you decrease T by one
The -- (decrement) operator will subtract from T each time the loop is run (after the loop condition is run since it as after T).
The simplest way is to just try it out:
public class Tester {
public static void main(String[] args) {
System.out.println("-------STARTING TESTER-------");
int T = 5;
while (T-- > 0) {
System.out.println(T);
}
System.out.println("-------ENDING TESTER-------");
}
}
Output:
-------STARTING TESTER-------
4
3
2
1
0
-------ENDING TESTER-------
If the -- operator was before T, the output would look like this (since it subtracts before the loop condition is run):
-------STARTING TESTER-------
4
3
2
1
-------ENDING TESTER-------
链接地址: http://www.djcxy.com/p/1980.html
上一篇: > Java中的符号?
下一篇: Java表达式