1

I have the below output from a loop in java, I would like to know as to how to set the gap between the columns so the output looks neat.

Name[Last,First]:Cruise, Tom     Movie:MI    Year:1990s     
Name[Last,First]:Hanks, Tom     Movie:Cast Away     Year:2000s   

I want the Movie and year to be aligned along the same line. I have used three methods getName() , getMovie, getYear() to obtain data.

0

2 Answers 2

4

try to use the tab character, If i remember right it will make it align nicely

\t

or Learn the printf, which is a shortcut for String.format();

System.out.printf("%12s%12s%n",hand1,h…

% = entity

s = String var placeholder

12 = spaces

%n = system independent line-end return

Sign up to request clarification or add additional context in comments.

Comments

1

Try to use format() or printf() method of the String class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.