0

how to print arrays even and odd numbers alternatively?

Example Input:{1,2,5,6,3,2} output:{2,1,2,3,6,5}

27th Mar 2018, 6:11 PM
karthick
8 ответов
+ 4
Job interview? If so, that isn't a big deal as long as you were honest about your Java knowledge. Pretend to be better than you are and you won't be hired. Lying about knowledge will be discovered and you won't be considered no matter how badly they need you. If they know the truth, they base hiring on how well they think you will fit in.
27th Mar 2018, 6:45 PM
John Wells
John Wells - avatar
+ 3
Is this homework? Maybe you missed the input should be sorted step. Sorting it would yield that output in your original post.
27th Mar 2018, 6:37 PM
John Wells
John Wells - avatar
+ 2
I would have expected output of: {2,1,6,5,2,3}. Nothing in your statement suggested jumping around in the array so the next even number from the beginning is 6.
27th Mar 2018, 6:25 PM
John Wells
John Wells - avatar
+ 2
I'd sort numbers as you insert them using a lists one odd the other even. I assume they only verify output so how you code it doesn't matter. https://www.geeksforgeeks.org/list-interface-java-examples/
27th Mar 2018, 9:03 PM
John Wells
John Wells - avatar
+ 1
Yes
27th Mar 2018, 6:33 PM
karthick
+ 1
No its asked in my interview, im not able to do this.
27th Mar 2018, 6:39 PM
karthick
+ 1
i would do it like this: split into 2 arrays odd & even, sort those arrays, and combine them back in one array alternating odd & even using a loop
27th Mar 2018, 8:09 PM
bedawang
bedawang - avatar
0
Its not job interview, its just online mock interview. Im new to java jus learning through sololearn. Jus tried for some online java test. If not interested to explain about this means jus you leave it. Don't discourage anyone and don't hurt anyone.
27th Mar 2018, 6:56 PM
karthick