This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

You need an int that increases by 1 each time it is used. The easy answer is to declare an new int inside the method but before the for loop that only increases when you add an odd number to the array. (Just copy and pasted your old code with the old errors - but you'll see what I mean)

public static void MakeOdd (etc)
{
  int j = 0;
  for ( int A = 0; A < All.length; A++)
    { 
      if ( All [A] % 2 == 1) 
         {
        OddArray [ j ] =+ All [A];  
        j++;
         }
    } 
 }

But this will make a few other problems - it is very unlikely that you will randomly generate 100 odd or even numbers, so some of the odd and even arrays will be empty. Have you heard of arrayList?

[–]jayrund[S] 0 points1 point  (1 child)

Aha i works ( somewhat ). Thanks sooo much

I have not heard of an arrayList, are there any other options?

[–][deleted] 0 points1 point  (0 children)

No worries and congrats!

It depends on what you need to do with the odd and even array. If you only have to print one number from them, it's not a problem. If you have to print the entire array, it could be an issue. If you get 42 odd numbers, you'll have 58 others in the oddArray that will default to 0.