Condicionales 7 y 8

This commit is contained in:
T-Royale committed 2026-09-24 16:37:34 +02:00
1 parent 41ffb994cd
commit 7097a445e7
8 files changed
+140 -87

No files matched your search

+15 -12
View File
@@ -5,17 +5,20 @@
import java.util.Scanner;
void main() {
Scanner sc = new Scanner(System.in);
final double monedas[] = {2, 1, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01};
Scanner sc = new Scanner(System.in);
// Monedas en centimos
final int[] monedas = { 200, 100, 50, 20, 10, 5, 2, 1 };
System.out.println("Cuantos euros quieres sacar?");
double euros = sc.nextDouble();
System.out.println("Cuantos euros quieres sacar?");
int centimos = (int) Math.round(sc.nextDouble() * 100);
for(int i = 0; euros != 0 && i < monedas.length;){
double moneda = monedas[i];
if(euros >= moneda){
System.out.printf("Dar moneda de %.2f€\n", moneda);
euros = Math.round((euros - moneda) * 100) / 100.0;
} else i++;
}
}
for (int i = 0; centimos != 0 && i < monedas.length;) {
int moneda = monedas[i];
if (centimos >= moneda) {
System.out.printf("Dar moneda de %.2f€\n", moneda / 100.0);
centimos -= moneda;
} else
i++;
}
sc.close();
}