Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.stream.IntStream;
- public class MoneyCounter {
- private static final int NOTE_VALUE = 0;
- private static final int NOTE_AMOUNT = 1;
- private static final int NUMBER_OF_AVAILABLE_NOTES = 9;
- public static void main(String[] args) {
- int[][] noteArray = new int[][] { {500,200,100,50,20,10,5,2,1}, {0,0,0,0,0,0,0,0,0} };
- // Textuelle Repraesentation der Banknotenwerte
- String[] noteNames = new String[] { "500$", "200$", "100$", "50$", "20$", "10$", "5$", "2$", "1$" };
- // an dieser Stelle wuerde eine Eingabe erfolgen.
- int amountToBeSplit = 999;
- // Splitte den Betrag auf die einzelnen Banknoten um
- int currIndex = 0;
- for (int currNoteValue : noteArray[NOTE_VALUE]) {
- noteArray[NOTE_AMOUNT][currIndex++] += amountToBeSplit / currNoteValue;
- amountToBeSplit %= currNoteValue;
- }
- // Hier wird ausgegeben
- IntStream.range(0, NUMBER_OF_AVAILABLE_NOTES - 1).forEach(currIndex ->
- System.out.println(noteNames[currIndex] + ": "
- + '\t' + noteArray[NOTE_AMOUNT][currIndex]));
- System.out.println("\n" + "Es wurden in Summe "
- + IntStream.of(noteArray[NOTE_AMOUNT]).sum()
- + " Scheine benoetigt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement