-
Lenguaje
Java usando Scanner
-
Descripción
Solicite nombre y edad de 3 de sus compañeros y devuelva el promedio de sus edades.
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
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
import java.util.Scanner;
public class EdadDe3Companeros {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int edad, i;
double promedio;
String nombre;
promedio = 0;
for (i=1; i<=3; 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();
promedio=promedio+edad;
System.out.println("Nombre: " + nombre);
System.out.println();
}
promedio=promedio/3;
System.out.println("Valor de promedio: " + promedio);
}
}
public class EdadDe3Companeros {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int edad, i;
double promedio;
String nombre;
promedio = 0;
for (i=1; i<=3; 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();
promedio=promedio+edad;
System.out.println("Nombre: " + nombre);
System.out.println();
}
promedio=promedio/3;
System.out.println("Valor de promedio: " + promedio);
}
}