-
Lenguaje
Java usando Scanner
-
Descripción
Solicite la edad y el sexo de un conjunto de n personas y determine:
a) Cuantas mujeres son mayores de edad.
b) Cuantos hombres son mayores de 60 años.
c) Cuantas mujeres son niñas (menos de 13 años).
d) Cuantos hombres son adolescentes (entre 13 y 17 años).
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
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
import java.util.Scanner;
public class EdadYGenero {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, d, edad;
int genero, i, n;
a = 0;
b = 0;
c = 0;
d = 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.print("Ingresa el valor de edad: ");
edad = in.nextInt();
in.nextLine();
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&&edad>=18)
a=a+1;
if(genero==2&&edad>60)
b=b+1;
if(genero==1&&edad<13)
c=c+1;
if(genero==2&&edad>=13&&edad<18)
d=d+1;
System.out.println();
}
System.out.println("Valor de a: " + a);
System.out.println("Valor de b: " + b);
System.out.println("Valor de c: " + c);
System.out.println("Valor de d: " + d);
}
}
public class EdadYGenero {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, d, edad;
int genero, i, n;
a = 0;
b = 0;
c = 0;
d = 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.print("Ingresa el valor de edad: ");
edad = in.nextInt();
in.nextLine();
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&&edad>=18)
a=a+1;
if(genero==2&&edad>60)
b=b+1;
if(genero==1&&edad<13)
c=c+1;
if(genero==2&&edad>=13&&edad<18)
d=d+1;
System.out.println();
}
System.out.println("Valor de a: " + a);
System.out.println("Valor de b: " + b);
System.out.println("Valor de c: " + c);
System.out.println("Valor de d: " + d);
}
}