使用扫描仪时找不到句子中的单词

问题描述 投票:1回答:1

我刚刚开始学习如何编写程序。在此程序中,我尝试使用扫描仪在句子中查找单词。但是我遇到了这个问题。导入java.util.Scanner;

公共类睾丸{静态扫描仪scn =新的扫描仪(System.in);

public static void main(String[] args) {
    if (pick == 5) {
        String sentenceFive = "i see you";
        String wordFive = "you";

        if (sentenceFive.contains(wordFive)) {
            System.out.println("Keyword matched the string");
        }

        else {
            System.out.println("No match");
        }
    }

    else if (pick == 6) {
        System.out.println("Please enter a sentence");
        String sentenceFive = scn.nextLine();
        scn.nextLine();
        System.out.println("Please enter a word");
        String wordFive = scn.nextLine();

        if (sentenceFive.contains(wordFive)) {
            System.out.println("Keyword matched the string");
        }

        else {
            System.out.println("No match");
        }

    }
}

}

(pick == 5)可以很好地工作,但是(pick == 6)返回“ No match”。if,else语句是相同的,我对(pick == 6)的输入也与(pick == 5)中的字符串相同。所以我想这可能是因为扫描仪问题?

是否有解决此问题的方法?预先谢谢!

java java.util.scanner
1个回答
0
投票

您得到了什么确切的错误?

© www.soinside.com 2019 - 2024. All rights reserved.