Java Programming Practice- A new 30 day challenge

It has been a long while since I worked on improving my technical knowledge or tried polishing my existing skills. Its never too late, so starting now. Here comes my latest 30 Day challenge. For coming 30 days, I will write one practice program everyday , compare it with other examples floating on the net, and find out what would have been a better way to do that.

The practice program of the day: Reverse the String passed to a method. Here is what I wrote:

 
The output of the program is something like this :
 gnirtS esreveR fo tset si sihT
 
Now for the better way of doing it:
Instead of converting to character Array and then looping through I could have used the charAt method of the String class directly inside the loop. Here is the updated version:
 
 
We can reverse an input String also using the inbuilt reverse() method of the Stringbuffer and StringBuilder. But here is one approach (using recursion) that caught my eye:
 
Wrapping up here, will be back again with a new program tomorrow.
 
 



Comments

Popular posts from this blog

Day#3 of Java Programming Practice- Longest word of a Sentence

Book Review: Those Pricey Thakur Girls

Day# 5 of Java Programming Practice- Change the first letter of each word in a sentence to Uppercase.