0
public class CounterAndSorter
{
    public static void main (String[] args)
    {
        int counter = 1;
        int oddSum = 0;
        int evenSum = 0;

        while(counter <= 25)
        {
            if(counter % 2 > 0)
            {
                oddSum += counter;
            }
            else
            {
                evenSum += counter;
            }

            counter++;
        }

        System.out.println("The sum of the even integers is " + evenSum);
        System.out.println("The sum of the odd integers is " + oddSum);
    }
}   

我最近开始使用 java 并试图编写一个程序来生成 100 个随机整数,然后将它们排序为偶数和奇数,并通过数组显示它们。我可以编译上面的代码,但无法执行。我不断收到越界异常。任何帮助,将不胜感激。

4

0 回答 0