k=(k>0)?(p++, k=0):k+1;
以上代码是什么意思?
摘自《Java与面向对象程序设计教程》印旻
p55,p56,p58,p61
问题点数:20、回复次数:4Top
1 楼onestab()回复于 2003-02-03 03:18:44 得分 0
excerpt from Thinking in java 2e:
The comma operator
Earlier in this chapter I stated that the comma operator (not the comma separator, which is used to separate definitions and function arguments) has only one use in Java: in the control expression of a for loop. In both the initialization and step portions of the control expression you can have a number of statements separated by commas, and those statements will be evaluated sequentially.
//: c03:CommaOperator.java
public class CommaOperator {
public static void main(String[] args) {
for(int i = 1, j = i + 10; i < 5;
i++, j = i * 2) {
System.out.println("i= " + i + " j= " + j);
}
}
} ///:~
>>> 在 ? : 中也可以用 "," 吗? k=(k>0)?(p++, k=0):k+1;Top
2 楼danceflash(Wine)回复于 2003-02-03 03:22:59 得分 10
好像是错的吧
记得Java中的逗号运算符只能用于"for"循环Top
3 楼danceflash(Wine)回复于 2003-02-03 03:23:47 得分 5
呵呵~~~
楼上好快的说^_^Top
4 楼marf_cn(吗啡)回复于 2003-02-03 15:02:48 得分 5
是啊Top




