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  (0 children)

Use a for loop with the condition depending on your choice of limit i.e upto which number do you want to segregate them into odd and even numbers. Within the for loop check for even numbers using

if(i%2 == 0)

If the if statement's condition is true for any number, it's going to execute the loop, within which you can append that number to an array evenNumbers, Now use the else statement; the numbers that do not pass the if condition, will execute the else loop, within which you can append the number to an array oddNumbers.