SCJP with label

醉酒当歌 提交于 2019-12-13 05:03:00

问题


Below will be compilation fail due to "label z is missing" but if I just move z: to one step below after o = o + 2 then that will work? What is the logic behind this?

public class Breaker {
static String o = "";

public static void main(String[] args) {
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);
}
}

回答1:


You cannot put the labels everywhere in the code. it should be only before statements. in this case labelname: for(;;){} Here's the documentation



来源:https://stackoverflow.com/questions/16666752/scjp-with-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!