Please help me to figure out what is wrong with my code. I tested it in Eclipse and I got correct output