public class Breaker { static String o = "";public static void main(String[] args) { 6.z:7.o = o + 2; 8.for(int x = 3; x < 8; x++) { 9.if(x==4) break; 10.if(x==6) break z; 11.o = o + x; 12.} 13.System.out.println(o); 14.} 15.}运行结果是(g)g)

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 09:53:17

public class Breaker { static String o = "";public static void main(String[] args) { 6.z:7.o = o + 2; 8.for(int x = 3; x < 8; x++) { 9.if(x==4) break; 10.if(x==6) break z; 11.o = o + x; 12.} 13.System.out.println(o); 14.} 15.}运行结果是(g)g)
public class Breaker { static String o = "";
public static void main(String[] args) {
6.z:
7.o = o + 2;
8.for(int x = 3; x < 8; x++) {
9.if(x==4) break;
10.if(x==6) break z;
11.o = o + x; 12.}
13.System.out.println(o); 14.} 15.}运行结果是(g)
g)Compilation fails.
报错说的是The label z is missing,label应该怎么定义啊,该怎么修改?

public class Breaker { static String o = "";public static void main(String[] args) { 6.z:7.o = o + 2; 8.for(int x = 3; x < 8; x++) { 9.if(x==4) break; 10.if(x==6) break z; 11.o = o + x; 12.} 13.System.out.println(o); 14.} 15.}运行结果是(g)g)
标签Z的范围你没确定,导致break Z 这句肯定出错,你把标签Z下面加个大括号就行了
z:
{
o = o + 2;
for(int x = 3; x < 8; x++) {
if(x==4) break;
if(x==6) break z;
o = o + x;
}
}
System.out.println(o);
}
}