k=(k>0)?(p++, k=0):k+1;

方工 2003-02-03 03:07:58
以上代码是什么意思?
摘自《Java与面向对象程序设计教程》印旻
p55,p56,p58,p61
...全文
126 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
danceflash 2003-02-03
  • 打赏
  • 举报
回复
呵呵~~~
楼上好快的说^_^
danceflash 2003-02-03
  • 打赏
  • 举报
回复
好像是错的吧
记得Java中的逗号运算符只能用于"for"循环
方工 2003-02-03
  • 打赏
  • 举报
回复
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;
marf_cn 2003-02-03
  • 打赏
  • 举报
回复
是啊

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧