-
Lenguaje
Java usando Scanner
-
Descripción
La secretaría de salud requiere un algoritmo que permita determinar qué tipo de vacuna (A, B o C) debe aplicar a una persona, considerando que si es mayor de 70 años, sin importar el sexo, se le aplica la tipo C; si tiene entre 16 y 69 años, y es mujer, se le aplica la B, y si es hombre, la A; si es menor de 16 años, se le aplica la tipo A, sin importar el sexo.
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
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
import java.util.Scanner;
public class VacunaDeTipoABYC {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int edad, sexo;
System.out.print("Ingresa el valor de edad: ");
edad = in.nextInt();
in.nextLine();
System.out.println("Selecciona el valor de sexo.");
System.out.println("\t1.- mujer");
System.out.println("\t2.- hombre");
System.out.print("\t: ");
do {
sexo = in.nextInt();
in.nextLine();
if (sexo<1||sexo>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (sexo<1||sexo>2);
if((sexo==2&&edad>=16&&edad<70)||edad<16)
System.out.println("A");
if(sexo==1&&edad>=16&&edad<70)
System.out.println("B");
if(edad>70)
System.out.println("C");
}
}
public class VacunaDeTipoABYC {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int edad, sexo;
System.out.print("Ingresa el valor de edad: ");
edad = in.nextInt();
in.nextLine();
System.out.println("Selecciona el valor de sexo.");
System.out.println("\t1.- mujer");
System.out.println("\t2.- hombre");
System.out.print("\t: ");
do {
sexo = in.nextInt();
in.nextLine();
if (sexo<1||sexo>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (sexo<1||sexo>2);
if((sexo==2&&edad>=16&&edad<70)||edad<16)
System.out.println("A");
if(sexo==1&&edad>=16&&edad<70)
System.out.println("B");
if(edad>70)
System.out.println("C");
}
}