Campbell Ritchie wrote:That might print negative numbers right, but I think it is no better as a solution, I am afraid.
Davey Lopez wrote:Question I thought you had to type super() to actually use a method from the base class
Jeanne Boyarsky wrote:Jitender,
Posting a code snippet is fine. Posting a hint is fine.
Campbell Ritchie wrote:Thank you for your comments. If somebody is trying to learn, they will be much more successful and remember the lesson better if they have worked it out for themselves. Simply giving a complete answer shortcircuits the process and ensures they do not know what to do next time such a problem arises.
We usually delete such posts (sometimes retaining the content so they can be restored later), but your posts both have instructive points about things which need improvement, so they are worth leaving.
We do actually care about beginners' questions; they usually go into a different forum, where we tell people this:-We have not done that to annoy you so sorry if we have. But turning up on a new forum, ignoring its conventions and calling people rude is really going to endear you to everybody, isn't it.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Winston Gutkowski wrote:
Jitender Raghuvanshi wrote:and you wont explain what is wrong with the code?
That's rude! :P
As rude as not reading our HowToAnswerQuestionsOnJavaRanch (←click) page before posting an answer?
Because if you had, you'd have seen our version of the Hippocratic oath: FirstRuleDoNoHarm (the first link).
And also: DontBeACodeMill.
However, I'm sure your intentions were great, and welcome to the Ranch, Jitender.
Anyway, its working fine at my end.
Except, as Campbell said (and I mentioned earlier), that code will NOT give you what you expect with negative numbers.
Campbell Ritchie wrote:I may have seen an error which is not there. Sorry. But have you tried it with -123?
Campbell Ritchie wrote:Welcome to the Ranch
We usually discourage people from posting the whole solution before the OP has a good chance to work it out, and delete posts or parts of posts which contain entire solutions, but I have decided to leave that code so people can see why it will not work properly.