public class Moedas { public static void main(String[] args) { final int Troco = 357; int Valor = 0; final int[] Moedas = { 100, 50, 25, 10, 5, 1 }; int moedasFinal = 0; for (int i = 0; i < Moedas.length; i++) { while (Valor < Troco) { Valor += Moedas[i]; moedasFinal += 1; if (Valor > Troco) { moedasFinal -= 1; Valor -= Moedas[i]; break; } else if (Valor == Troco) { System.out.println(moedasFinal); return; } } } } }