String Formatting <p>I am currently trying to construct a program that prints Pascal's Triangles at different heights through calling a method to construct the triangle with an int parameter for height of the triangle. When trying to run my program, the first Pascal's triangle prints bu then I get an Exception error, reading this:</p> <pre><code>java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags = 0 at java.util.Formatter$FormatSpecifier.failMismatch(Unknown Source) at java.util.Formatter$FormatSpecifier.checkBadFlags(Unknown Source) at java.util.Formatter$FormatSpecifier.checkGeneral(Unknown Source) at java.util.Formatter$FormatSpecifier.&lt;init&gt;(Unknown Source) at java.util.Formatter.parse(Unknown Source) at java.util.Formatter.format(Unknown Source) at java.io.PrintStream.format(Unknown Source) at PascalsTriangle.drawTriangle(PascalsTriangle.java:19) at PascalsTriangle.main(PascalsTriangle.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272) </code></pre> <blockquote> <p></p> </blockquote> <p>Through debugging, I noticed that there is an issue with how I formatted the String output in line 19. I am fairly new to Java programming and I have tried to work through different formatting issues in my code, but I have been stumped on how to make this work. Any suggestions on how I can prevent this exception error from happening?</p> <p>Here is the code to my program:</p> <pre><code>public class PascalsTriangle { private int height; public void drawTriangle(int height) { System.out.println("A Pascal Triangle with height " + height); for(int i = 0; i &lt;= height; i++) { int number = 1; System.out.format("%" + ((height-i) * 2) + "s", " "); for(int j = 0; j &lt;= i; j++) { System.out.format("%5d", number); number = number * (i - j) / (j + 1); } System.out.println(); } } public static void main(String[] args) { PascalsTriangle pascal = new PascalsTriangle(); pascal.drawTriangle(4); pascal.drawTriangle(10); pascal.drawTriangle(7); pascal.drawTriangle(2); } } </code></pre>