This week's book giveaway is in the Web Services forum.We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Bear Bibeault
• Devaka Cooray
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Knute Snortum
• Junilu Lacar
• paul wheaton
Saloon Keepers:
• Ganesh Patekar
• Frits Walraven
• Tim Moores
• Ron McLeod
• Carey Brown
Bartenders:
• Stephan van Hulst
• salvin francis
• Tim Holloway

# Program not giving the expected output

Greenhorn
Posts: 19

ex.PNG

Marshal
Posts: 61810
193
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.

Greenhorn
Posts: 3
A small error also leads to unexpected results, make sure you are not wrong.

Gnanagowthaman sankar
Greenhorn
Posts: 19

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]

Campbell Ritchie
Marshal
Posts: 61810
193
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?

Gnanagowthaman sankar
Greenhorn
Posts: 19

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

Campbell Ritchie
Marshal
Posts: 61810
193

Gnanagowthaman sankar wrote:. . . Array-3 fix34

Thank you

How far have you got with the algorithm?

Gnanagowthaman sankar
Greenhorn
Posts: 19

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