Nuevos ejercicios del bloque 2
This commit is contained in:
33
src/bloque02/masCondicionales/Ejercicio1.java
Normal file
33
src/bloque02/masCondicionales/Ejercicio1.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package bloque02.masCondicionales;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Ejercicio1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int tempNumber;
|
||||
int numNegativos = 0;
|
||||
int numBajos = 0; //Números entre 0 y 25 ambos incluidos
|
||||
int numMedios = 0; //Números entre 26 y 250 ambos incluidos
|
||||
int numGrandes = 0; //Mayores de 250
|
||||
|
||||
for (int i = 1; i < 6; i++) {
|
||||
System.out.println("Introduzca el " + i + "º número:");
|
||||
tempNumber = sc.nextInt();
|
||||
if (tempNumber < 0) {
|
||||
numNegativos = numNegativos + tempNumber;
|
||||
} else if (tempNumber > 250) {
|
||||
numGrandes = numGrandes + tempNumber;
|
||||
} else if (tempNumber > 25) {
|
||||
numMedios = numMedios + tempNumber;
|
||||
} else {
|
||||
numBajos = numBajos + tempNumber;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("La suma de los números negativos es: " + numNegativos);
|
||||
System.out.println("La suma de los números bajos es: " + numBajos);
|
||||
System.out.println("La suma de los números medios es: " + numMedios);
|
||||
System.out.println("La suma de los números grandes es: " + numGrandes);
|
||||
}
|
||||
}
|
||||
33
src/bloque02/masCondicionales/Ejercicio2.java
Normal file
33
src/bloque02/masCondicionales/Ejercicio2.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package bloque02.masCondicionales;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Ejercicio2 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int tempNumber;
|
||||
int numNegativos = 0;
|
||||
int numBajos = 0; //Números entre 0 y 25 ambos incluidos
|
||||
int numMedios = 0; //Números entre 26 y 250 ambos incluidos
|
||||
int numGrandes = 0; //Mayores de 250
|
||||
|
||||
for (int i = 1; i < 6; i++) {
|
||||
System.out.println("Introduzca el " + i + "º número:");
|
||||
tempNumber = sc.nextInt();
|
||||
if (tempNumber < 0) {
|
||||
numNegativos++;
|
||||
} else if (tempNumber > 250) {
|
||||
numGrandes++;
|
||||
} else if (tempNumber > 25) {
|
||||
numMedios++;
|
||||
} else {
|
||||
numBajos++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Has introducido " + numNegativos + " números negativos." );
|
||||
System.out.println("Has introducido " + numBajos + " números bajos. ");
|
||||
System.out.println("Has introducido " + numMedios + " números medios." );
|
||||
System.out.println("Has introducido " + numGrandes + " números grandes. ");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user