Files
Estudos/exercicios-java/Moedas.java
Caio1w eeb36002bd Feito um novo exercicio com java usando Scanner
Scanner equivalente ao input do python
2025-11-02 22:14:08 -03:00

26 lines
553 B
Java

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;
}
}
}
}
}