为什么它不会循环?

Why wont it loop?

非常感谢,但现在它没有添加正确的价格,而是将其保持在第一个添加的数量,例如它应该是 6.99 +.20 +.20+.20,具体取决于我添加的数量

 public void addToppings() 
        {
            String[] topChoice = {"Pepperoni", "Mushrooms", "Pineapple", "Bacon", "Beef Bites(IDK)"};
            int add;
            String topPick = " ";
            String total = " ";
            double price = 0;
            int index = 0;

                do 
                    {
                       topPick = (String)JOptionPane.showInputDialog(null,"What toppings do you want?","Add Your Toppings", JOptionPane.QUESTION_MESSAGE, null, topChoice, topChoice[0]);

                       if ((topPick != null) && (topPick.length() > 0))
                                {
                                    price += 0.20;
                                    index++;
                                }

                    add = JOptionPane.showConfirmDialog(null,"Would you like to add more toppings?","More Toppings",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);           
                    }


                while (add == JOptionPane.YES_OPTION);

                    return;
   }

移动这条线

topPick = (String)JOptionPane.showInputDialog(null, "What toppings do you want?","Add Your Toppings", JOptionPane.QUESTION_MESSAGE, null, topChoice, topChoice[0]);

进入你的 do while 循环。