-
Lenguaje
Java usando Scanner
-
Descripción
Determinar cuántos hombres y cuántas mujeres se encuentran en un grupo de n personas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class CantidadDeHombresYMujeres {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int genero, hombres, i, mujeres, n;
hombres = 0;
mujeres = 0;
System.out.print("Ingresa el valor de n: ");
n = in.nextInt();
in.nextLine();
for (i=1; i<=n; i++) {
System.out.print("PROCESO " + i);
System.out.println("Selecciona el valor de genero.");
System.out.println("\t1.- Mujer");
System.out.println("\t2.- Hombre");
System.out.print("\t: ");
do {
genero = in.nextInt();
in.nextLine();
if (genero<1||genero>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (genero<1||genero>2);
if(genero==1)
mujeres=mujeres+1;
else
hombres=hombres+1;
System.out.println();
}
System.out.println("Valor de hombres: " + hombres);
System.out.println("Valor de mujeres: " + mujeres);
}
}
public class CantidadDeHombresYMujeres {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int genero, hombres, i, mujeres, n;
hombres = 0;
mujeres = 0;
System.out.print("Ingresa el valor de n: ");
n = in.nextInt();
in.nextLine();
for (i=1; i<=n; i++) {
System.out.print("PROCESO " + i);
System.out.println("Selecciona el valor de genero.");
System.out.println("\t1.- Mujer");
System.out.println("\t2.- Hombre");
System.out.print("\t: ");
do {
genero = in.nextInt();
in.nextLine();
if (genero<1||genero>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (genero<1||genero>2);
if(genero==1)
mujeres=mujeres+1;
else
hombres=hombres+1;
System.out.println();
}
System.out.println("Valor de hombres: " + hombres);
System.out.println("Valor de mujeres: " + mujeres);
}
}