I am working on a application for figuring how much of each kind of coin One should get back when they give say 99 cents as the amount of change. I have a way to do it which involves simple integer division and subtraction but i was wondering if anyone knew a way to do it with the modulus operator to make it less bulky

Member Avatar
int change = 99;
		int[] coins = { 25, 10, 5, 1 };
		
		for (int coin : coins) {
			int count = change >= coin ? change / coin : 0;
			change = count > 0 ? change - count * coin : change;
			System.out.println(coin + ": " + count);
		}