Bucles 1-9
This commit is contained in:
1 parent
cf7bb1f1b9
commit
2e8c5cae24
10 files changed
+441770
No files matched your search
@@ -0,0 +1,22 @@
|
||||
// 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);
|
||||
int i = 0;
|
||||
while (i++ < 100) {
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user