我正在尝试制作哈利波特法术游戏

0 java arrays

玩家应该从系列中输入一个咒语,如果它在数组中,计算机将在数组中输出一个不同的咒语.如果它不在数组内,它将打印数组中的第一个咒语,依此类推.

我用4个法术测试了这个,但它总是输出"Crucio".我不知道为什么会这样!
请帮忙.

这是我到目前为止:

public class HarryPotterGame {

    public static void main(String[] args) {
        System.out.println("---------------------------------------");
        System.out.println("Welcome to the Harry Potter Spell Game!");
        System.out.println("---------------------------------------");

            String[] Spells;
            Spells = new String[] {"Accio","AvadaKedavra","Crucio","Imperio"};

            System.out.println("Your turn. Do not use spaces!");
            Scanner sn = new Scanner(System.in);
            String Spell1 = sn.nextLine(); 
            int i = 0;

            while(Spells[i] != Spell1){


                if (i == 4){
                    System.out.println("Accio");
                }
                i++;
            break;

            }

            System.out.println(Spells[i+1]);
Run Code Online (Sandbox Code Playgroud)

Gus*_*tek 7

使用equals方法比较字符串

while(!Spells[i].equals(Spell1)){
Run Code Online (Sandbox Code Playgroud)