title: java.util.IllegalFormatPrecisionException error when rounding to the two-decimal places using printf
body: <p>I'm a new java coder and am getting an error when using <code>printf</code> to round a value to twodecimal places. Can anyone help me understand why, and how to resolve the error?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>import java.util.Scanner;
  
  public class Demo
  {
  
      public static void main(String[] args)
      {
  
          int age = 0;
          int count = 0;
          int round = 0;
  
  
          while ((age &lt; 12) || (age &gt; 18))
          {
  
              Scanner input = new Scanner(System.in);
              System.out.print("Enter a non-teen age: ");
              age = input.nextInt();          
  
              if ((age &lt; 12) || (age &gt; 18))
              {
                  count = count + 1;
                  round = round + age;
              }
          }
  
          System.out.println("Opps! " + age + " is a teen's age.");
          System.out.println("Number of non-teens entered: " + count);
          System.out.printf("Average of non-teens ages entered: %.2d",       round);
      }
  
  
  }
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
  <pre><code>Exception in thread "main" java.util.IllegalFormatPrecisionException: 2
  at java.util.Formatter$FormatSpecifier.checkInteger(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 java.io.PrintStream.printf(Unknown Source)
   Demo.main(Demo.java:31)
  </code></pre>
  </blockquote>