-
Lenguaje
Java usando Scanner
-
Descripción
Lea para un grupo de N personas el nombre, la edad y el deporte (1= fútbol, 2= baloncesto, 3= otro deporte) e imprima:
a) cuantos de fútbol son mayores de edad
b) cuantos de baloncesto son menores de edad
c) cuantas personas prefieren otro deporte.
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
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
import java.util.Scanner;
public class EstadisticasDeDeportes {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, deporte, edad;
int i, n;
String nombre;
a = 0;
b = 0;
c = 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 nombre: ");
nombre = in.nextLine();
System.out.print("Ingresa el valor de edad: ");
edad = in.nextInt();
in.nextLine();
in.nextLine();
System.out.println("Selecciona el valor de deporte.");
System.out.println("\t1.- f\u00FAtbol");
System.out.println("\t2.- baloncesto");
System.out.println("\t3.- otro deporte");
System.out.print("\t: ");
do {
deporte = in.nextInt();
in.nextLine();
if (deporte<1||deporte>3)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (deporte<1||deporte>3);
if(deporte==1&&edad>=18)
a=a+1;
if(deporte==2&&edad<18)
b=b+1;
if(deporte==3)
c=c+1;
System.out.println("Nombre: " + nombre);
System.out.println();
}
System.out.println("Valor de a: " + a);
System.out.println("Valor de b: " + b);
System.out.println("Valor de c: " + c);
}
}
public class EstadisticasDeDeportes {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, deporte, edad;
int i, n;
String nombre;
a = 0;
b = 0;
c = 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 nombre: ");
nombre = in.nextLine();
System.out.print("Ingresa el valor de edad: ");
edad = in.nextInt();
in.nextLine();
in.nextLine();
System.out.println("Selecciona el valor de deporte.");
System.out.println("\t1.- f\u00FAtbol");
System.out.println("\t2.- baloncesto");
System.out.println("\t3.- otro deporte");
System.out.print("\t: ");
do {
deporte = in.nextInt();
in.nextLine();
if (deporte<1||deporte>3)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (deporte<1||deporte>3);
if(deporte==1&&edad>=18)
a=a+1;
if(deporte==2&&edad<18)
b=b+1;
if(deporte==3)
c=c+1;
System.out.println("Nombre: " + nombre);
System.out.println();
}
System.out.println("Valor de a: " + a);
System.out.println("Valor de b: " + b);
System.out.println("Valor de c: " + c);
}
}