This week's book giveaway is in the Big Data forum. We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line! See this thread for details.

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;

You might want to work on this section of your code:

If I understand you correctly, if all you had was one dollar, then you would want your output to be simply "Your amount $1.00 consists of one dollar". If that's the case, let me give you a couple of hints to point you in the right direction. You should actually check out the StringBuffer class to do this with, since it's more efficient. In any event, what you might think about when building your output String is checking if your amount of a particular currency is greater than zero, and if it is, append the appropriate text to your String or StringBuffer. If you initialize your StringBuffer eariler, you actually already have your if statements in place to determine whether or not to append anything to the StringBuffer, and what you should append. HTH [ November 07, 2003: Message edited by: Jason Menard ]