In java there are two types to print output print and println. In this problem you have use println which print the output of the next command on next line but in the problem it is given that you have to print on the same line thus you should use print instead of println.