views:

80

answers:

3

Hey there. I am trying to return an array, but the compiler is telling me that it's an incompatible type..?

My code: http://pastie.org/private/v4xn4eahkojftsghudf1g

I'm a beginner at Java, sorry about this :)

Thanks very much.

+4  A: 

im guessing you're talking about

static int getOddList(int[] a);

the return type is set to int, should be int[]

ie:

static int[] getOddList(int[] a)

it's the same with the other functions you're returning arrays. needs to be int[], not int

John Boker
Oh boy, I can't believe it was that simple of an issue. All fixed, now I just have some logic stuff to fix :)Thanks so much!
alainmeyer1
Since it looks like you're new here you should probably mark this as the solution :)
John Boker
Oh yes... Where would I do this?EDIT: Nevermind, got it :) Thanks!
alainmeyer1
+3  A: 

For the following methods:

static int getOddList(int[] a)
static int getEvenList(int[] a)

You've declared the methods as returning single integer values although in the code for the methods you're actually returning:

 return oddList;
 return evenList;

Both of those variables are declared as int[] xxxxxx = new int[10];

You'll want to change the method signatures for both getOddList and getEvenList to:

static int[] getOddList(int[] a)
static int[] getEvenList(int[] a)

One question I do have to ask is in your main method, you're just calling the getXXXX methods without storing the results.

  // Create and print arrays from input
  getNegativeList(input);
  getOddList(input);
  getEvenList(input);

If you're not going to be storing the results of the method call, it may make more sense to declare the method signatures of getOddList and getEvenList as:

static void getOddList(int[] a)
static void getEvenList(int[] a)

Then, you'd update the code for the method not to return any values.

Again, that's just a suggestion. If you are planning on storing the results of those methods but just haven't got around to writing that code yet then you should be fine just changing int to int[] for the return types of the two mentioned methods.

Brian Hasden
+1  A: 

And before you ask: you should probably declare your total variables outside your for loop, if you're intending to keep just the odd numbers, etc.

J. Polak
Haha, whoops! Thanks, didn't catch that :)
alainmeyer1