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个随机整数,然后将它们分类为偶数和赔率并通过数组显示它们。我可以编译上面的代码但是无法执行它。我不断收到Out of Bounds Exception。任何帮助将不胜感激。