How can I use System.out.format() to display multiple items on one line in Java?
<pre><code>import java.text.*;
public class program17
{
public static void main(String[] args)
{
    NumberFormat money=NumberFormat.getCurrencyInstance();
    int[] num={2013,2015,2017,2019,2021};
    double[] price={19.85,15.39,16.59,12.35,15.15};
    int[] qty={43,12,34,17,10};
    double[] value={0,0,0,0,0};
    System.out.println("Part  \tItem \tItem    \tTotal");
    System.out.println("Number\tPrice\tQuantity\tValue\n");
    for(int i=0;i&lt;5;i++)
    {
        value[i]=val(price[i],qty[i]);
        //System.out.println(num[i]+"\t"+money.format(price[i])+"\t"+qty[i]+"\t"+money.format(value[i]));
        System.out.format("%4d\t $%5d.2f\t %2d\t %6.2f", num[i], price[i], qty[i], value[i]);
    }
}
public static double val(double p, int q)
{
    double x=p*q;
    return x;
}
}
</code></pre>

<p>Here is 100% of my code.
Here is the output of my solution:
<img src="http://maradastudios.ucoz.com/school/Capture2.png" alt="Captured Output"></p>

<p>As you may be able to tell, I could simply display the "data lines" of this program with the System.out.println() statement, however, I have already had need of System.out.format() in this particular type of situation, so I decided it would be best to actually learn what this error means.
I THINK it may be because my variable price[i] that I am attempting to display is a double, rather than an int, like num[i].  I came to this conclusion because at first, I ran it with </p>

<pre><code>System.out.format("%4d\t", num[i);
</code></pre>

<p>after that worked fine, I ran it with</p>

<pre><code>System.out.format("%4d\t $%5d.2f\t", num[i], price[i);
</code></pre>

<p>and got an error after that. This is the complete code that I am attempting to run.  Could anyone tell me what the problem is with my System.out.format() statement, and assist me as I correct it?</p>
