From 682db9c618be59a1f565290e263f4005fe711645 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Sat, 25 Feb 2023 15:27:14 +0000 Subject: [PATCH] Switch from 'while' loop to 'do..while' --- 1ano/2semestre/poo/src/aula02/RealNumbers.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/1ano/2semestre/poo/src/aula02/RealNumbers.java b/1ano/2semestre/poo/src/aula02/RealNumbers.java index 76969bf..9b4675f 100644 --- a/1ano/2semestre/poo/src/aula02/RealNumbers.java +++ b/1ano/2semestre/poo/src/aula02/RealNumbers.java @@ -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);