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);
}
even and odd array
Page 1 of 16 Replies - 370 Views - Last Post: 17 April 2012 - 07:28 PM
#1
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
Replies To: even and odd array
#3
Re: even and odd array
Posted 16 April 2012 - 08:00 PM
#4
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.
#5
Re: even and odd array
Posted 16 April 2012 - 08:06 PM
DimitriV, 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
#6
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:
At least, on line 14 was the array error. Not sure about line 11.
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.
#7
Re: even and odd array
Posted 17 April 2012 - 07:28 PM
Page 1 of 1
|
|

New Topic/Question
This topic is locked



MultiQuote



|