I am having a problem with the following exercise out of my University text book. I have figured out how to do everything except how to not display 0 amounts. Any help would be appreciated. Please bear with the length.

Thanks.

import javax.swing.JOptionPane;

public class Exercise3_1 {

/** Main method */

public static void main(

String[] args) {

int amount; // Amount entered from the keyboard

// Receive the amount entered from the keyboard

String amountString = JOptionPane.showInputDialog(null,

"Enter an amount in integer, for example 1156",

"Compute Change", JOptionPane.QUESTION_MESSAGE);

// Convert string to integer

amount = Integer.parseInt(amountString);

int remainingAmount = amount;

// Find the number of one dollars

int numOfOneDollars = remainingAmount / 100;

remainingAmount = remainingAmount % 100;

// Find the number of quarters in the remaining amount

int numOfQuarters = remainingAmount / 25;

remainingAmount = remainingAmount % 25;

// Find the number of dimes in the remaining amount

int numOfDimes = remainingAmount / 10;

remainingAmount = remainingAmount % 10;

// Find the number of nickels in the remaining amount

int numOfNickels = remainingAmount / 5;

remainingAmount = remainingAmount % 5;

// Find the number of pennies in the remaining amount

int numOfPennies = remainingAmount;

String dollar = "";

String quarter = "";

String dime = "";

String nickel = "";

String penny = "";

if (numOfOneDollars == 0)

dollar = "";

else

dollar = (numOfOneDollars == 1) ? " Dollar" : " Dollars";

if (numOfQuarters == 0)

quarter = "";

else

quarter = (numOfQuarters == 1) ? " Quarter" : " Quarters";

if (numOfDimes == 0)

dime = "";

else

dime = (numOfDimes == 1) ? " Dime" : " Dimes";

if (numOfNickels == 0)

nickel = "";

else

nickel = (numOfNickels == 1) ? " Nickel" : " Nickels";

if (numOfPennies == 0)

penny = "";

else

penny = (numOfPennies ==1) ? " Penny" : " Pennies";

// Display results

String output = "Your amount " + amount + " consists of \n" +

numOfOneDollars + dollar + " \n" +

numOfQuarters + quarter + " \n" +

numOfDimes + dime + " \n" +

numOfNickels + nickel + " \n" +

numOfPennies + penny;

JOptionPane.showMessageDialog(null, output,

"Example 2.4 Output", JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}