A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李会成 中级黑马   /  2013-1-28 16:52  /  1190 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


  1. class Exercise01
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 int i = 1,d;
  6.                 for(System.out.println("a"),d = 1;i < 3;System.out.println("b"))
  7.                 {
  8.                         System.out.println("c");
  9.                          i++;
  10.                 }
  11.                 for(System.out.print("a"),int a = 1;a <3,System.out.print("b");System.out.print("c"))
  12.                 {
  13.                         i++;
  14.                         System.out.println("我是换行");
  15.                 }
  16.         }
  17. }
复制代码
为什么第一个for正常运行,第二个for却是编译出错了呢?

4 个回复

倒序浏览
   for(System.out.print("a"),int a = 1;a <3,System.out.print("b");System.out.print("c"))

for 中间那个判断要返回真假的才可以的......不然你咋判断??????System.out.print("b")这个没真假的意思吧

评分

参与人数 1黑马币 +9 收起 理由
Rancho_Gump + 9

查看全部评分

回复 使用道具 举报
  for(System.out.print("a"),int a = 1;a <3,System.out.print("b");System.out.print("c"))//亲第一个表达式和第二个表达式这里应该是分号不是逗号

13.                {

14.                        i++;

15.                        System.out.println("我是换行");

16.                }

回复 使用道具 举报
14.14.1 The basic for Statement
The basic for statement executes some initialization code, then executes an
Expression
, a Statement, and some update code repeatedly until the value of the
Expression is false.
    BasicForStatement:
    for ( ForInitopt ; Expressionopt ; ForUpdateopt ) Statement
    ForStatementNoShortIf:
    for ( ForInitopt ; Expressionopt ; ForUpdateopt )
      StatementNoShortIf
ForInit:
   StatementExpressionList
   LocalVariableDeclaration
ForUpdate:
  StatementExpressionList
StatementExpressionList:
  StatementExpression
  StatementExpressionList , StatementExpression
The Expression must have type boolean or Boolean, or a compile-time error
occurs.
回复 使用道具 举报
请勿复制他人帖子,技术分不是入学的门槛而是为了帮助大家学习而存在的。

请勿再次发此类帖子了!

此贴就关闭了。此后如有再次发现直接封禁处理,请看到此贴的会员也加以注意。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马