-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromedios.java
More file actions
54 lines (46 loc) · 1.68 KB
/
Promedios.java
File metadata and controls
54 lines (46 loc) · 1.68 KB
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
50
51
52
53
54
/*Crear un programa que calcule el promedio de cinco notas positivas ingresadas por teclado.
*/
import java.util.InputMismatchException;
import java.util.Scanner;
public class Promedios {
public static void main(String[] args) {
double note = 0;
double notes = 0;
int quantity = 0;
Scanner scanner = new Scanner(System.in);
while (true) {
try {
System.out.println("Ingrese la cantidad de notas a evaluar: ");
quantity = scanner.nextInt();
if (quantity <= 0) {
System.out.println("Ingrese un intervalo valido.");
} else {
break;
}
} catch (InputMismatchException e) {
System.out.println("Error: Debes ingresar un valor válido");
scanner.next();
}
}
for (int i = 1; i <= quantity; ) {
System.out.println("Ingrese la nota " + i + ":");
try {
note = scanner.nextDouble();
if (note < 1 || note > 7) {
System.out.println("Ingrese una nota válida.");
} else {
notes += note;
i++;
}
} catch (InputMismatchException e) {
System.out.println("Error: Debes ingresar un valor válido");
scanner.next();
}
}
double result = 0;
result = notes / quantity;
System.out.println("Resultados Estudiante");
System.out.println("Prmedio Final: " + result);
System.out.println("Notas: " + quantity);
}
}