So I'm reading Java Concepts Late Edition for my coding class and I just got to the formatting section. There is a practice prompt and I can't get it right and I don't understand why.
The goal is to print a table of prices with prices being print with 2 digits after the decimal point.
import java.util.Scanner;
public class Table
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Unit price: ");
double price = in.nextDouble();
System.out.println("Quantity Price");
int quantity = 1;
System.out.printf("%d %.2f", quantity, quantity * price);
quantity = 12;
System.out.printf("%d %.2f", quantity, quantity * price);
quantity = 100;
System.out.printf("%d %.2f", quantity, quantity * price);
}
}
This is my code
Unit price: Quantity Price
1 19.9512 239.40100 1995.00"**
This is my output
Unit price: Quantity Price
1 19.95
12 239.40
100 1995.00"
This is the expected output
I don't know what I did wrong. Can someone please help!