-
Lenguaje
Java usando Scanner
-
Descripción
Un maestro desea saber qué porcentaje de hombres y qué porcentaje de mujeres hay en un grupo de estudiantes.
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
public class PorcentajeDeMujeresYHombres {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int estudiantes, genero, hombres, mujeres;
double porcentaje_hombres, porcentaje_mujeres;
String tecla_repetir;
estudiantes = 0;
hombres = 0;
mujeres = 0;
porcentaje_hombres = 0;
porcentaje_mujeres = 0;
do {
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();
do {
System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
tecla_repetir = in.nextLine();
} while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
} while (tecla_repetir.equalsIgnoreCase("s"));
estudiantes=hombres+mujeres;
if (estudiantes == 0) {
porcentaje_hombres = 0;
} else {
porcentaje_hombres=100.0*hombres/estudiantes;
}
if (estudiantes == 0) {
porcentaje_mujeres = 0;
} else {
porcentaje_mujeres=100.0*mujeres/estudiantes;
}
System.out.println("Valor de estudiantes: " + estudiantes);
System.out.println("Valor de hombres: " + hombres);
System.out.println("Valor de mujeres: " + mujeres);
System.out.println("Valor de porcentaje hombres: " + porcentaje_hombres);
System.out.println("Valor de porcentaje mujeres: " + porcentaje_mujeres);
}
}
public class PorcentajeDeMujeresYHombres {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int estudiantes, genero, hombres, mujeres;
double porcentaje_hombres, porcentaje_mujeres;
String tecla_repetir;
estudiantes = 0;
hombres = 0;
mujeres = 0;
porcentaje_hombres = 0;
porcentaje_mujeres = 0;
do {
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();
do {
System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
tecla_repetir = in.nextLine();
} while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
} while (tecla_repetir.equalsIgnoreCase("s"));
estudiantes=hombres+mujeres;
if (estudiantes == 0) {
porcentaje_hombres = 0;
} else {
porcentaje_hombres=100.0*hombres/estudiantes;
}
if (estudiantes == 0) {
porcentaje_mujeres = 0;
} else {
porcentaje_mujeres=100.0*mujeres/estudiantes;
}
System.out.println("Valor de estudiantes: " + estudiantes);
System.out.println("Valor de hombres: " + hombres);
System.out.println("Valor de mujeres: " + mujeres);
System.out.println("Valor de porcentaje hombres: " + porcentaje_hombres);
System.out.println("Valor de porcentaje mujeres: " + porcentaje_mujeres);
}
}