继续循环直到字符串匹配

时间:2017-02-27 20:40:30

标签: java for-loop

我正在寻找一种方法来继续for循环,直到字符串匹配。

update

基本上,字符串i循环就像

1panda,2boom,3tnt.

问题是当字符串不以2开头时,我想继续下一个字符串。 我不能使用return语句,因为它会停止循环。 还有其他想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用continue;What is the "continue" keyword and how does it work in Java?

for (int i = 0; i < 100; i++ ) {
    if(i % 2 == 0) {
        continue;
    } else {
        System.out.println(i);
    }
}

仅打印奇数。显然,这是一个人为的例子,因为你可以在if(i % 2 !=)上完成打印,但我希望你明白这一点。

相关问题