Switch from 'while' loop to 'do..while'

This commit is contained in:
TiagoRG 2023-02-25 15:27:14 +00:00
parent befd8f5b71
commit 682db9c618
1 changed files with 4 additions and 5 deletions

View File

@ -16,17 +16,16 @@ public class RealNumbers {
double min = first;
double sum = first;
while (true) {
double n = sin.nextDouble();
if (n == first)
break;
double n;
do {
n = sin.nextDouble();
if (n > max)
max = n;
if (n < min)
min = n;
sum += n;
++readNumbers;
}
} while (n != first);
System.out.printf("Valor máximo: %f\nValor mínimo: %f\nMédia: %f\nTotal: %f\n", max, min, (float) sum/readNumbers, sum);