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
• Liutauras Vilda
• Bear Bibeault
• Tim Cooke
• Junilu Lacar
Sheriffs:
• Paul Clapham
• Devaka Cooray
• Knute Snortum
Saloon Keepers:
• Ron McLeod
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Frits Walraven
Bartenders:
• Carey Brown
• salvin francis
• Claude Moore

Program not giving the expected output

Greenhorn
Posts: 19

ex.PNG

Marshal
Posts: 64182
215
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: 64182
215
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: 64182
215

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