title: IllegalFormatPrecisionException while trying to format string
body: <p>I'm trying to write a program which prompts the user to enter two 3×3 matrices and displays their product.</p>
  
  <p>For example, a user can enter:</p>
  
  <pre>
  Matrix A: 2 4 6 8 10 12 14 16 18
  Matrix B: 1 2 3 4 5.6 6.6 7.4 8.1 9
  </pre>
  
  <p>Below is what I have tried, but I keep getting this error. Any help to point me in the right direction would be appreciated. I'm trying to get it to one decimal place:</p>
  
  <pre>
  Exception in thread "main" java.util.IllegalFormatPrecisionException: 2
      at java.util.Formatter$FormatSpecifier.checkInteger(Formatter.java:2892)
      at java.util.Formatter$FormatSpecifier.(Formatter.java:2643)
      at java.util.Formatter.parse(Formatter.java:2480)
      at java.util.Formatter.format(Formatter.java:2414)
      at java.io.PrintStream.format(PrintStream.java:920)
      at java.io.PrintStream.printf(PrintStream.java:821)
      at Exercise6_25.main(Exercise6_25.java:55)
  </pre>
  
  <hr>
  
  <pre><code>import java.util.Scanner;
  
  public class matrixCalc
  {
      public static void main(String args[])
      {
          Scanner s= new Scanner(System.in);
  
          int i,j,k;
          int n=3;
  
          double a[][]= new double[n][n];
          double b[][]= new double[n][n];
          double c[][]= new double[n][n];
  
          System.out.println("enter the array elements of a:");
  
          for(i=0;i&lt;n;i++)
          {
              for(j=0;j&lt;n;j++)
              {
                  a[i][j]=s.nextDouble();
              }
              System.out.print(" ");
          }
  
          System.out.println(" "); 
          System.out.println("enter the array elements of b:");
  
          for(i=0;i&lt;n;i++)
          {
              for(j=0;j&lt;n;j++)
              {
                  b[i][j]=s.nextDouble();
              }
              System.out.print(" ");
          }
  
          System.out.println(" ");
          System.out.println("the result matrix is:");
  
          for(i=0;i&lt;n;i++)
          {
              for(j=0;j&lt;n;j++)
              {
                  for(k=0;k&lt;n;k++)
                  {
                      c[i][j]+=a[i][k]*b[k][j];
                  }
              }
          }
  
          for(i=0;i&lt;n;i++)
          {
              for(j=0;j&lt;n;j++)
              {
                  System.out.printf("%.2d", c[i][j]+" ");
              }
              System.out.println();
          }
      }
  }
  </code></pre>