Wednesday, 15 April 2015

Format java string to look a specific way -



Format java string to look a specific way -

i new java , have 4 int stacks need print out in specific way. ide using bluej.

i want print arrays following

|110| |231| |333| |444| |111| |232| |334| |447| |112| |233| |335| |448| |113| |234| |336| |449| |114| |235| |337| |450| |115| |236| |338| |451|

i trying system.out.println("|"+stack1.pop()+"|") creates problem because not sure how go bottom, top. ex. 115 --> 231. each column represents stack.

thank you!

use string.format() improve concatenating bunch of strings

system.out.println(string.format("|%s|\t|%s|\t|%s|\t|%s|", stack1.pop(),stack2.pop(),stack3.pop(),stack4.pop()));

if want print stack elements in opposite order, reverse stack first

java string-formatting

No comments:

Post a Comment