I need some help in modifying this prime number generator code. How do I modify this code so that it assigns prime numbers to an array and returns it?
I have tried to get it work but it won't, so please help me.
Expand|Select|Wrap|Line Numbers
- class Prime2
- {
- int[] array = new int[25];
- public int[] Primes() {
- int i = 0;
- for (i = 0; i < array.length; i++)
- {
- int x, y = 0;
- for( x = 2; x < 100; x++ )
- {
- if( x % 2 != 0 || x == 2 )
- {
- for( y = 2; y <= x / 2; y++ )
- {
- if( x % y == 0 )
- {
- break;
- }
- }
- if( y > x / 2 )
- {
- array[i] = x;
- }
- }
- }
- }
- return array;
- }
- public static void main (String[] args) {
- Prime2 numbers = new Prime2();
- System.out.println(numbers.Primes());
- }
- }
- maks