Actividad bucles

This commit is contained in:
T-Royale committed 2026-10-02 14:14:12 +02:00
1 parent 42ccb65310
commit 2faefaef88
20 files changed
+341

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
// Diseña un algoritmo que lea 100 números y cuente los positivos, negativos y nulos y muestre
// los totales
import java.util.Scanner;
void main() {
int positivos = 0, negativos = 0, nulos = 0;
System.out.println("Introduce 100 numeros: ");
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 100; i++) {
int n = sc.nextInt();
if (n > 0)
positivos++;
else if (n < 0) {
negativos++;
} else
nulos++;
}
sc.close();
System.out.printf("positivos: %d\nnegativos: %d\nnulos: %d\n", positivos, negativos, nulos);
}