• Post Reply Bookmark Topic Watch Topic
  • New Topic
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  RSS feed

 
Greenhorn
Posts: 19
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ex.PNG
[Thumbnail for ex.PNG]
output
 
Marshal
Posts: 61691
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A small error also leads to unexpected results, make sure you are not wrong.
 
Gnanagowthaman sankar
Greenhorn
Posts: 19
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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: 61691
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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: 61691
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gnanagowthaman sankar wrote:. . . Array-3 fix34

Thank you

How far have you got with the algorithm?
 
Gnanagowthaman sankar
Greenhorn
Posts: 19
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!