Java Output Formatting Hackerrank Solution