while循环不重复

时间:2017-05-27 17:17:26

标签: java chatbot

我想让用户再次输入一个输入,如果他拼错了#34;我很伤心"并完成整个转换过程。

当我输入" imsed"它说"我不明白"因为它应该并要求另一个输入,但是当我输入另一个输入时,它就会结束。

我还不能使用数组。

do {
    if (a.contains("sad")) {
        System.out.println("bot: " + "Hey there! Dont be sad, Here is a pun to cheer you up");
        System.out.println();
        i = 1 + dice.nextInt(3);
        switch (i) { // start of switch 

            case 1:
                System.out.println("Why did the traffic light felt embarrased?\n" 
                    + "Because everyone saw it changing");
                a = input.nextLine();
                break;

            case 2:
                System.out.println("Why was Cinderella thrown off the basketball team?"
                    + "\nShe ran away from the ball.");
                a = input.nextLine();
                break;

            case 3:
                System.out.println("Why is Peter Pan always flying?\n"
                    + "He neverlands.");
                a = input.nextLine();
                break;
        } //end of  switch
    } else if (a.contains("again")) {
        e = 1 + dice.nextInt(3);
        switch (e) { // start of switch 

            case 1:
                System.out.println("How do you know it's an emotional wedding?\n" + "When the cake is in tiers");
                a = input.nextLine();
                break;

            case 2:
                System.out.println("What does a house wear?" + "\nA Dress.");
                a = input.nextLine();
                break;

            case 3:
                System.out.println("How do you know a frenchmen plays video games?\n" + "He says wii when you ask him.");
                a = input.nextLine();
                break;
        } //end of  switch
    }
} while (a.equals("again")


if (a.contains("im happy")) {
    System.out.println("bot: " + "Have a great day ahead!");
}
if (!a.equals("im sad")
    || !a.equals("im happy"
    || !a.equals("again")) {
    System.out.println("bot: " + "I don't understand");
    a = input.nextLine();
}

0 个答案:

没有答案