sai rama krishna wrote:In my mind i was thinking i was able solve this challenge in 25 lines of code within in main method itself rather than introducing new 5 to 10 new methods but apparently writing all in main with 25 simple lines is not good idea in terms of readability to others or even to me later stages?
Never judge the code by its length, nor think shorter - better. Judge by readability, how quickly you can find the things in the code which are responsible for particular tasks. Your code will need to be read by others, and when you write your code in a main method, no one can understand it - except you, not for long too as it gets forgotten when time gets passed.
Always concentrate on clarity - and when there is just a beginning for you, I'd say - more methods better. Most important thing is - that singular method would do that one thing what it says only.
printAsTriangle it should print numbers as triangle, no more no less.
goToNextLine needs to do what it says, just simply go to next line.
printLine too, it is a bit abstract, but then again, you digging down and you see specifics, sub-parts of this task, not the other different task, but sub-task, it is important.
And always try follow such approach and you'll notice how much easier is to cope with complexity, because at a given time you need to concentrate on a tiny piece of work.