蓝色第23课可以在这里使用for循环吗?

时间:2019-04-06 19:24:05

标签: java for-loop while-loop

我正在尝试检测句子t1中字符串sen []中敏感单词的每个标记,但似乎不适用于for循环

package IntelliJ.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner kbReader = new Scanner(System.in);
        System.out.println("Enter next sentence: ");
        String s1 = kbReader.next();

        StringTokenizer t1 = new StringTokenizer(s1, " ");
        String sen[] = {"Hermes", "bridge", "Muddy", "River", "assault", "offensive"};
        boolean Reject = false;


        while (t1.hasMoreTokens()) {
            String m = t1.nextToken();
            int i;
            for (i = 0; i < 6; i++) {
                if (m.equalsIgnoreCase(sen[i])) {
                    Reject = true;
                }
            }
        }
        if (Reject)
            System.out.println(">>>REJECTED");
        else
            System.out.println("OK");
    }
}

0 个答案:

没有答案