
The second loop runs through the arrays again. The first loop runs through both arrays and finds the length of the longest string in either array. For example, you can take two string arrays and display their contents in two parallel columns using two loops.

Loops are particularly useful when trying to achieve even spacing between multiple strings. However, you can instead use a combination of loops to achieve more complex spacing without the need for complicated format strings. The Formatting class requires extensive knowledge of the strings used to define the output format. The final line of code "()" moves the cursor to the next line of code.

The "d" in the format string indicates that the output value is a decimal integer. If the integer is only two characters long, the other two characters will be blank spaces. The "%4" in the first section of the format string indicates that the program should use four characters to print each integer.

To print three integer values with a maximum of three characters in each and a single space in between, use the following code: The first input is a string representing the formatting that should be applied to the output, and the second input is the output itself. Outputting a formatted segment of text is simple - rather than using "()," use "()." The format method takes two inputs instead of the single input that the print method uses. If you output several values with the same formatting options, you can ensure that they will take up the same space in the output line. With the Formatter, you can define the maximum width of a value, and the Formatter then automatically pads the value with empty spaces to make sure it is the same width.

Java's Formatter class allows you to format data before it is output.
