Saturday, October 30, 2010

Odd or even

Last couple of weeks were comparatively cool in the office because we had delivered a stable build of our application to QA team.Like in any other software company, the free hours turned into the learning sessions.Some peoples started learning new technologies and some utilized the time to strengthen their basics in programming.

Our circle is into refreshing the programming logics.Everybody were into screen development in the project and started forgetting the real coding which does problem solving using logics.The refreshing session started with famous sql questions such as how to find out the duplicates in a table,how to insert values into table without duplication using single line query etc…After some time it reached to .net coding.The first question was simple.

Display the string “Odd” or “Even” for a given number without using any conditional operators,looping and built-in or custom methods .NO GOOGLING!!!

Oh its simple…The first response was this.But after sometime people recognized that they forget even how to find whether a number is odd or they forgot the operator “%”.Remember that they are the senior developers who are designing their tracks.

If one person learns how to ride a bicycle or learns swimming he will not forget it in his life time.In his older ages he may not perform due to health problems.But the knowledge will be there with him.The same principle applies in the case of programming too…It took some time to get answers.

The first answer was the traditional one.Use an array.

MessageBox.Show(new string[] { "Even", "Odd" }[inputVale % 2]);

Next answer was to use enumeration

public enum Result
MessageBox.Show(((Result)(inputVale % 2)).ToString());

There is a small confusion…ToString() is a built in function???The next answer was also using function.

MessageBox.Show((inputVale % 2).ToString().Replace("0","Even").Replace("1","Odd"));

A humble request to all developers who are working on the screen development, please don’t spoil your real coding skills…

No comments: