【发布时间】:2012-09-10 23:05:09
【问题描述】:
我想创建这样的逻辑:如果 s2 为 null,则调试器会跳过所有复杂的字符串操作并返回 null 而不是 s1 + s2 + s3,如第一个 if 块中所示。我在某个地方错了吗?
public static String helloWorld(String s1, String s2, String s3){
if(s2==null){
continue;
return null;
}
... lots of string manipulation involving s1, s2 and s3.
return (s1+s2+s3);
}
【问题讨论】:
-
您需要一个循环才能使用
continue。 -
@bouncingHippo:您是否有兴趣仅跳过空字符串,或者如果 s2 是空字符串(“” - 这不是空字符串),您是否还想返回 null
-
是的,我想在 s2==null 时返回 null,而 s2=""
标签: java algorithm iteration continue