创建一个程序来生成随机数并将它们放入偶数或奇数数组中,但得到相同的错误消息?如果有人知道如何更好地格式化,请帮助!
import static java.lang.Math.*;
import java.util.Random;
public class Unit8
{
public static void main ( String [ ] args )
{
int [ ] randomNum = new int [100] ;
for ( int x = 0; x <= randomNum.length; x++ )
{
randomNum [ x ] = (int) (Math.random ( ) * 25 );
}
int sum = 0;
int [ ] oddArray = new int [ 100 ] ;
for ( int x = 0; x <= randomNum.length; x++ )
{
if (randomNum [ x ] % 2 != 0 )
sum += oddArray [ x ];
}
int sum2 = 0;
int [ ] evenArray = new int [ 100 ] ;
for ( int x = 0; x <= randomNum.length; x++ )
{
if (randomNum [ x ] % 2 == 0 )
sum2 += evenArray [ x ] ;
}
display ( oddArray );
display1 ( evenArray );
}
public static void display ( int [ ] oddArray)
{
System.out.println ( oddArray );
}
public static void display1 ( int [ ] evenArray )
{
System.out.println ( evenArray );
}
}