class fortest
{
public static void main (String[] args)
{
for (int x = 1,(System.out.println("b"));x<3;System.out.println("b"),x++) //初始化表达式部分变更
{
System.out.println("c");
}
}
}
--------------------error----------------------------------------
:\javawork\lesson2>javac lckz.java
ckz.java:46: 需要 <标识符>
for (int x = 1,(System.out.println("b"));x<3;System.out.println(
b"),x++)
^
ckz.java:46: 需要 ';'
for (int x = 1,(System.out.println("b"));x<3;System.out.println(
b"),x++)
^
ckz.java:46: 非法的类型开始
for (int x = 1,(System.out.println("b"));x<3;System.out.println(
b"),x++)
^
ckz.java:46: 不是语句
for (int x = 1,(System.out.println("b"));x<3;System.out.println(
b"),x++)
^
ckz.java:46: 需要 ';'
for (int x = 1,(System.out.println("b"));x<3;System.out.println(
b"),x++)
^
ckz.java:46: 需要 ';'
for (int x = 1,(System.out.println("b"));x<3;System.out.println(
b"),x++)
^
错误
------------------下面的代码通过①-------------------------------------
class fortest
{
public static void main (String[] args)
{
for (int x = 1,y=0;x<3;System.out.println("b"),x++) //初始化表达式部分变更
{
System.out.println("c");
System.out.println("y="+y);
}
}
}
------------------下面的代码通过②-------------------------------------
class fortest
{
public static void main (String[] args)
{
int x = 1,y=0;
for (System.out.println("i"),System.out.println("o");x<3;System.out.println("b"),x++) //初始化表达式部分变更
{
System.out.println("c");
System.out.println("y="+y);
}
}
}