A friendly place for programming greenhorns!
Program not giving the expected output

ex.PNG
output
Welcome to the Ranch

You appear to have arrived in the wrong place, but don't worry: I can move you somewhere more appropriate.
Please always tell us where such questions come from: is that from codingbat? Please explain the question you have to solve, not the expected output. Then we shall have enough information to help.
A small error also leads to unexpected results, make sure you are not wrong.

Gnanagowthaman sankar wrote:
Return an array that contains exactly the same numbers as the given array, but rearranged so that every 3 is immediately followed by a 4. Do not move the 3's, but every other number may move. The array contains the same number of 3's and 4's, every 3 has a number after it that is not a 3, and a 3 appears in the array before any 4.

fix34([1, 3, 1, 4]) → [1, 3, 4, 1]
fix34([1, 3, 1, 4, 4, 3, 1]) → [1, 3, 4, 1, 1, 3, 4]
fix34([3, 2, 2, 4]) → [3, 4, 2, 2]

Forget about the code. Draw those arrays and go through the process of moving the 4 with a pencil. Then write down, again without using any code, explaining the algorithm. Only when you have done that should you consider writing any code.

And again, is that a codingbat exercise? Which number?

Campbell Ritchie wrote:Forget about the code. Draw those arrays and go through the process of moving the 4 with a pencil. Then write down, again without using any code, explaining the algorithm. Only when you have done that should you consider writing any code.

And again, is that a codingbat exercise? Which number?

Array-3 fix34

Gnanagowthaman sankar wrote:. . . Array-3 fix34

Thank you

How far have you got with the algorithm?

Campbell Ritchie wrote:

Gnanagowthaman sankar wrote:. . . Array-3 fix34

Thank you

How far have you got with the algorithm?

Campbell Ritchie wrote:You want to tell and help me

No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS

This thread has been viewed 2418 times.

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2018 17:52:05.