Compare commits
2 Commits
80fe6d08db
...
11990b1919
| Author | SHA1 | Date | |
|---|---|---|---|
| 11990b1919 | |||
| c5bc334e75 |
21
src/capitulo03/bloque03/Ejercicio1.java
Normal file
21
src/capitulo03/bloque03/Ejercicio1.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package capitulo03.bloque03;
|
||||||
|
|
||||||
|
import static capitulo03.utils.Utils.solicitarIntScanner;
|
||||||
|
|
||||||
|
public class Ejercicio1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num = -1, suma = 0, i;
|
||||||
|
|
||||||
|
for (i = -1; num != 0; i++) {
|
||||||
|
num = solicitarIntScanner("Introduzca el siguiente número: (Si pone 0, terminará el programa)");
|
||||||
|
if (i == -1 && num != 0) {
|
||||||
|
suma = num;
|
||||||
|
} else if (num != 0) {
|
||||||
|
suma += num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("La suma de los números introducidos es: " + suma);
|
||||||
|
System.out.println("La media de los números introducidos es: " + (suma / (float) i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
23
src/capitulo03/bloque03/Ejercicio2.java
Normal file
23
src/capitulo03/bloque03/Ejercicio2.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package capitulo03.bloque03;
|
||||||
|
|
||||||
|
import static capitulo03.utils.Utils.solicitarIntScanner;
|
||||||
|
|
||||||
|
public class Ejercicio2 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num = -1, mayor = 0, menor = 0;
|
||||||
|
|
||||||
|
for (int i = 0; num != 0; i++) {
|
||||||
|
num = solicitarIntScanner("Introduzca el siguiente número: (Si pone 0, terminará el programa)");
|
||||||
|
if (i == 0 && num != 0) {
|
||||||
|
mayor = num;
|
||||||
|
menor = num;
|
||||||
|
} else if (num != 0) {
|
||||||
|
if (num > mayor) mayor = num;
|
||||||
|
if (num < menor) menor = num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("El mayor número de los números introducidos es: " + mayor);
|
||||||
|
System.out.println("El menor número de los números introducidos es: " + menor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
19
src/capitulo03/bloque03/Ejercicio3.java
Normal file
19
src/capitulo03/bloque03/Ejercicio3.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package capitulo03.bloque03;
|
||||||
|
|
||||||
|
import static capitulo03.utils.Utils.solicitarIntScanner;
|
||||||
|
|
||||||
|
public class Ejercicio3 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num = -1;
|
||||||
|
|
||||||
|
for (int i = 0; num != 0; i++) {
|
||||||
|
num = solicitarIntScanner("Introduzca el siguiente número: (Si pone 0, terminará el programa)");
|
||||||
|
if (num != 0) {
|
||||||
|
for (int j = 1; j < 11; j++) {
|
||||||
|
System.out.println(num + " x " + j + " = " + (num * j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
20
src/capitulo03/bloque03/Ejercicio4.java
Normal file
20
src/capitulo03/bloque03/Ejercicio4.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package capitulo03.bloque03;
|
||||||
|
|
||||||
|
import static capitulo03.utils.Utils.solicitarIntScanner;
|
||||||
|
|
||||||
|
public class Ejercicio4 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num = -1, cuentaPositivos = 0, cuentaNegativos = 0;
|
||||||
|
|
||||||
|
for (int i = 0; num != 0; i++) {
|
||||||
|
num = solicitarIntScanner("Introduzca el siguiente número: (Si pone 0, terminará el programa)");
|
||||||
|
if (num != 0) {
|
||||||
|
if (num > 0) cuentaPositivos++;
|
||||||
|
if (num < 0) cuentaNegativos++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("La cantidad de números positivos es: " + cuentaPositivos);
|
||||||
|
System.out.println("La cantidad de números negativos es: " + cuentaNegativos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
11
src/capitulo03/utils/Utils.java
Normal file
11
src/capitulo03/utils/Utils.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package capitulo03.utils;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
public static int solicitarIntScanner(String pregunta) {
|
||||||
|
System.out.println(pregunta);
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
return sc.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user