英文:
I don't understand why i get the orphaned error near default in my code
问题
switch(countryCode){
case "GB":
validLength = 22;
break;
case "GR":
validLength = 27;
break;
case "SA":
validLength = 24;
break;
case "CH":
validLength = 21;
break;
case "TR":
validLength = 26;
break;
default:
System.out.println("Unknown country code: " + iban.substring(0,2));
return -1;
}
请注意,您提供的代码存在一些错误。我已经尝试保留原始的代码结构和错误,同时进行了翻译。如果您需要关于修复错误的帮助,请随时告诉我。
英文:
switch(countryCode){
case "GB":
validLength = 22;
break;
case "GR":
validLength = 27;
break;
break;
case "SA":
validLength = 24;
break;
case "CH":
validLength = 21;
break;
case "TR":
validLength = 26;
break;
}
break;
default:
System.out.println("Unknown country code: " + iban.substring(0,2));
return -1;
I have a small bit of code here and keep getting the orphaned error near default and I can't seem to understand or fix it
答案1
得分: 2
default
分支应该位于花括号内,与其他 case
分支并列。
switch (countryCode) {
case "GB":
validLength = 22;
break;
case "GR":
validLength = 27;
break;
case "SA":
validLength = 24;
break;
case "CH":
validLength = 21;
break;
case "TR":
validLength = 26;
break;
default:
System.out.println("未知的国家代码:" + iban.substring(0, 2));
return -1;
}
英文:
The default
cause should be inside the curly braces alongside the other case
s.
switch (countryCode) {
case "GB":
validLength = 22;
break;
case "GR":
validLength = 27;
break;
case "SA":
validLength = 24;
break;
case "CH":
validLength = 21;
break;
case "TR":
validLength = 26;
break;
default:
System.out.println("Unknown country code: " + iban.substring(0,2));
return -1;
}
答案2
得分: 0
默认情况必须位于您的switch语句的花括号内,因为它是"default-case"。<br>
而在default语句之前的"break;"语句也没有意义 - break用于退出switch语句代码,并继续执行花括号外的下一条语句。
英文:
default has to be inside the brackets of your switch statement, because it is the "default-case".<br>
The "break;" statement right before your default-statement makes also no sense - break is used to leave the switch-statement code and continue with the next statement outside the brackets of the switch.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论