java program to input a amount and find it's denomination
Answers
Answered by
2
Explanation:
public static void countCurrency(int amount)
{
int[] notes = new int[]{ 2000, 500, 200, 100, 50, 20, 10, 5, 1 };
int[] noteCounter = new int[9];
// count notes using Greedy approach
for (int i = 0; i < 9; i++) {
if (amount >= notes[i]) {
noteCounter[i] = amount / notes[i];
amount = amount - noteCounter[i] * notes[i];
}
}
// Print notes
System.out.println("Currency Count ->");
for (int i = 0; i < 9; i++) {
if (noteCounter[i] != 0) {
System.out.println(notes[i] + " : "
+ noteCounter[i]);
}
}
}
Similar questions
Math,
1 month ago
History,
1 month ago
Hindi,
1 month ago
Political Science,
9 months ago
English,
9 months ago