-4

为此,我想编写一个程序,让一个人输入动物解决了多少个谜题并存储这些值并将它们加在一起

我将如何实现记录每只动物解决的谜题数量并将它们加在一起的东西?

例如:

动物 1 解决了多少个谜题?5

动物 2 解决了多少个谜题?2

动物 3 解决了多少个谜题?1

动物 4 解决了多少个谜题?3

这些动物共解决了 11 个谜题

     for(int puzzleNum = 1; puzzleNum <= 4; puzzleNum++)

     {
         textinput = JOptionPane.showInputDialog("How many puzzles did animal "  + mazeNum + " solve?");

         mazesSolved = Integer.parseInt(textinput);

   }
4

2 回答 2

0

你只是在路上把它加起来。

int mazesSolved = 0;   
for(int puzzleNum = 1; puzzleNum <= 4; puzzleNum++)
{
    textinput = JOptionPane.showInputDialog("How many puzzles did animal "  + mazeNum + "solve?");
    mazesSolved += Integer.parseInt(textinput);
}
于 2013-10-28T15:43:33.067 回答
0
int mazesSolved = 0;

for(int puzzleNum = 1; puzzleNum <= 4; puzzleNum++)
{
     textinput = JOptionPane.showInputDialog("How many puzzles did animal "  + mazeNum + " solve?");
     mazesSolved += Integer.parseInt(textinput);
}
于 2013-10-28T15:43:56.233 回答