小编use*_*003的帖子

Java while循环永远不会进入循环

我正在用java写一个视频扑克,我需要问玩家是否要从他们手中取出任何牌.我为此写了一个while循环,但它没有像现在这样的方式工作.如果有人能把我送到正确的方向,我会很感激 - 我还是java的新手......谢谢.(这counter是因为玩家不会删除超过5张牌)

    String response = "y";
    int counter = 0;
    System.out.println("Remove any cards?");
    System.out.println("Enter y for 'yes' and n for 'no'");
    response = input.nextLine();
    while((response != "n") && (counter < 5))
    {

        System.out.println("Enter the number of a card to be removed (1-5)");
        int l = input.nextInt();
        p.removeCard(p.getHand().get(l-1));
        p.addCard(cards.deal());
        cards.incrementTop();
        counter ++;
        System.out.println("Card removed. More? Type 'yes' or 'no'");
        String answer = input.nextLine();
        if (answer == "no")
            {
                response = "n";
            }       
    }  
Run Code Online (Sandbox Code Playgroud)

java while-loop

0
推荐指数
1
解决办法
81
查看次数

标签 统计

java ×1

while-loop ×1