even and odd array

Page 1 of 1

6 Replies - 719 Views - Last Post: 17 April 2012 - 07:28 PM Rate Topic: -----

#1 ola3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 17-February 12

even and odd array

Posted 16 April 2012 - 07:56 PM

What im trying to do is to put the odd and even integers in separate arrays



  public static void main(String[] args){
    int [] number= new int[]{1,2,3,4,5,6,7,8,9};
    int[] even;
    int[] odd;
    even = new int[10];
    odd = new int[10];
    for( int i=0; i<number.length;i++){
      if(number[i]%2==0){
        number[i]+=even;
      }
      else
        number[i]=odd;
    }
    System.out.println(odd);
  }


Is This A Good Question/Topic? 0
  • +

Replies To: even and odd array

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: even and odd array

Posted 16 April 2012 - 07:59 PM

What's the issue?
Was This Post Helpful? 0
  • +
  • -

#3 ola3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 17-February 12

Re: even and odd array

Posted 16 April 2012 - 08:00 PM

View PostDimitriV, on 16 April 2012 - 07:59 PM, said:

What's the issue?

i keep getting an error
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: even and odd array

Posted 16 April 2012 - 08:02 PM

I'm guessing it is where you try to print the array. I really can't tell, please post the errors.
Was This Post Helpful? 0
  • +
  • -

#5 ola3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 17-February 12

Re: even and odd array

Posted 16 April 2012 - 08:06 PM

View PostDimitriV, on 16 April 2012 - 08:02 PM, said:

I'm guessing it is where you try to print the array. I really can't tell, please post the errors.

no its not, the error is coming from where i am trying to load the even numbers into the array that says even and the odd numbers into the array that says odd


File: C:\Users\Chimaroke\Desktop\Rahman\Computer science\spring 2012\Homework\findeven.java [line: 11]
Error: C:\Users\Chimaroke\Desktop\Rahman\Computer science\spring 2012\Homework\findeven.java:11: incompatible types
found : int[]
required: int
File: C:\Users\Chimaroke\Desktop\Rahman\Computer science\spring 2012\Homework\findeven.java [line: 14]
Error: C:\Users\Chimaroke\Desktop\Rahman\Computer science\spring 2012\Homework\findeven.java:14: incompatible types
found : int[]
required: int
Was This Post Helpful? 0
  • +
  • -

#6 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: even and odd array

Posted 16 April 2012 - 08:12 PM

I think it's because you're printing an array, not an jnt. Try this:
for (int i = 0, i < odd.Length - 1, i++){
System.out.print(odd[i]);
}



At least, on line 14 was the array error. Not sure about line 11.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: even and odd array

Posted 17 April 2012 - 07:28 PM

issue resolved in
http://www.dreaminco...-from-an-array/

Avoid double posting
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1