-
Lenguaje
Java usando Scanner
-
Descripción
Digitar 5 números por pantalla y calcular e imprimir, la suma y el promedio de los números digitados.
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
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
import java.util.Scanner;
public class SumaYPromedioDe5Numeros {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double a, b, c, d, e;
double promedio, suma;
System.out.print("Ingresa el valor de a: ");
a = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de b: ");
b = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de c: ");
c = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de d: ");
d = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de e: ");
e = in.nextDouble();
in.nextLine();
suma=a+b+c+d+e;
promedio=suma/5;
System.out.println("Valor de promedio: " + promedio);
System.out.println("Valor de suma: " + suma);
}
}
public class SumaYPromedioDe5Numeros {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double a, b, c, d, e;
double promedio, suma;
System.out.print("Ingresa el valor de a: ");
a = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de b: ");
b = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de c: ");
c = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de d: ");
d = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de e: ");
e = in.nextDouble();
in.nextLine();
suma=a+b+c+d+e;
promedio=suma/5;
System.out.println("Valor de promedio: " + promedio);
System.out.println("Valor de suma: " + suma);
}
}