Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '%'
Java Result: 1
Here is the code!
// Exercise 7.20 Solution: Sales2.java
// Program totals sales for salespeople and products.
public class Sales2
public static void main( String args )
Scanner input = new Scanner( System.in );
// sales array holds data on number of each product sold
// by each salesperson
double sales = new double[ 5 ][ 4 ]; // 5 salespeople, 4 products each person
System.out.print( "Enter salesperson number (-1 to end): " );
int person = input.nextInt(); // the salesperson index
while ( person != -1 )
// To do
// prompt to enter product number and save it as an integer
System.out.print("Please enter the product number: ");
int product = input.nextInt();
// promp to enter sales amont and save it as double
System.out.print("Please enter the sales amount: ");
double salesAmount = input.nextDouble();
// error-check the input number for the array boundary
//error check input
if (person >= 1 && person < 5 && product >=1 && product < 6 &&
salesAmount >= 0)
sales[product -1][person -1] =+ salesAmount;
System.out.print("Enter sales person number(-1 to end):");
person = input.nextInt();
double salesPersonTotal = new double;
//display data table
for (int column = 0; column < 4; column ++)
salesPersonTotal[column] = 0;
What am I missing??? The table does not want to show.
Edit: Forgot problem spec
7.20 (Total Sales) Use a two-dimensional array to solve the following problem: A company has
four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each type of product sold. Each slip contains the following:
a) The salesperson number
b) The product number
c) The total dollar value of that product sold that day
Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write an application that will read all this information for last month’s sales and summarize the total sales by salesperson and by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, display the results in tabular format, with each column representing a particular salesperson and each row representing a particular product. Cross-total each row to get the total sales of each product for last month. Cross-total each column to get the total sales by salesperson for last month. Your tabular output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.
Check out the % signs in these three statements. The second and third ones will work but not as intended (the 8 and 14.2 will be printed as-is, not be used for formatting), the first one is plain wrong. If you need to include a literal % sign you must duplicate it: %%.