Hello,
I am working on a program that generates 100 random integers and then sorts them into even and odd. When i go to compile the program, it tells me that it cannot find variables randonum, evennum, and oddnum. I'm new to arrays so i'm guessing i declared/ defined them wrong. Thanks in advance for the help, i'm looking forward to becoming a part of the community!
import static java.lang.Math.*;
public class ArrayEvenOdd
{
public static void main (String []args)
{
int evencount = 0;
int oddcount = 0;
int evennum [ ] = new int [ 100 ] ;
int oddnum [ ] = new int [ 100 ];
int randonum [ ] = new int [ 100 ];
for (int j = 0; j < randonum.length; j++ ) {
randonum [j] = (int) ( random() * 25);
}
for (int y = 0; y < randomum.length; y++ ){
if (randonum [y] % 2 == 0) {
evennum( y, evencount );
evencount++;
} else {
oddnum( y, oddcount );
oddcount++;
System.out.println( "The even numbers were:" );
display ( evennum );
System.out.println();
System.out.println( "The odd numbers were:" );
display ( oddnum );
}
}
}
public static int [] evennum( int num, int count )
{
evennum [ count ] = randonum [ num ];
return evennum;
}
public static int [] oddnum( int num, int count )
{
oddnum [ count ] = randonum [ num ];
return oddnum;
}
public static void display( int array[] )
{
for (int j = 0; j < array.length; j++ )
if ( array [ j ] != 0) {
System.out.println( array[j] );
}
}
}