import java.util.* ;
import java.lang.* ;
import java.io.* ;
public class Main {
/*3.Fazer um algoritmo que:
•Leia um número indeterminado de linhas contendo cada uma a idade de um indivíduo.
•A última linha que não entrará nos cálculos, contém o valor da idade igual a zero.
•Calcule e escreva a idade média deste grupo de indivíduos.
•Escreva também a maior idade e a menor*/
public static void main
( String [ ] args
) { Scanner s
= new Scanner
( System .
in ) ; ArrayList< Integer> lista = new ArrayList<> ( ) ;
int soma = 0 ;
int menor = 999 ;
int maior = 0 ;
System .
out .
println ( "Digite 0 para terminar" ) ;
for ( ;; ) {
System .
out .
println ( "Digite um número: " ) ; int num = s.nextInt ( ) ;
if ( num == 0 ) {
break ;
}
lista.add ( num) ;
soma += num;
maior
= Math .
max ( maior, num
) ; menor
= Math .
min ( menor, num
) ; }
}
System .
out .
println ( "A média de idade é " + ( soma
/ lista.
size ( ) ) ) ; System .
out .
println ( "A maior idade é " + maior
) ; System .
out .
println ( "A menor idade é " + menor
) ; }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpwdWJsaWMgY2xhc3MgTWFpbiB7Ci8qMy5GYXplciB1bSBhbGdvcml0bW8gcXVlOgrigKJMZWlhIHVtIG7Dum1lcm8gaW5kZXRlcm1pbmFkbyBkZSBsaW5oYXMgY29udGVuZG8gY2FkYSB1bWEgYSBpZGFkZSBkZSB1bSBpbmRpdsOtZHVvLgrigKJBIMO6bHRpbWEgbGluaGEgcXVlIG7Do28gZW50cmFyw6Egbm9zIGPDoWxjdWxvcywgY29udMOpbSBvIHZhbG9yIGRhIGlkYWRlIGlndWFsIGEgemVyby4K4oCiQ2FsY3VsZSBlIGVzY3JldmEgYSBpZGFkZSBtw6lkaWEgZGVzdGUgZ3J1cG8gZGUgaW5kaXbDrWR1b3MuCuKAokVzY3JldmEgdGFtYsOpbSBhIG1haW9yIGlkYWRlIGUgYSBtZW5vciovCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgU2Nhbm5lciBzID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKICAgICAgICBBcnJheUxpc3Q8SW50ZWdlcj4gbGlzdGEgPSBuZXcgQXJyYXlMaXN0PD4oKTsKICAgICAgICBpbnQgc29tYSA9IDA7CiAgICAgICAgaW50IG1lbm9yID0gOTk5OwogICAgICAgIGludCBtYWlvciA9IDA7CgogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiRGlnaXRlIDAgcGFyYSB0ZXJtaW5hciIpOwoKICAgICAgICBmb3IgKDs7KSB7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiRGlnaXRlIHVtIG7Dum1lcm86ICIpOwogICAgICAgICAgICBpbnQgbnVtID0gcy5uZXh0SW50KCk7IAogICAgICAgICAgICBpZihudW0gPT0gMCkgewogICAgICAgICAgICAJYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbGlzdGEuYWRkKG51bSk7CiAgICAgICAgICAgIHNvbWEgKz0gbnVtOwogICAgICAgICAgICBtYWlvciA9IE1hdGgubWF4KG1haW9yLCBudW0pOwogICAgICAgICAgICBtZW5vciA9IE1hdGgubWluKCBtZW5vciwgbnVtKTsKICAgICAgICB9CiAgICAgICAgZm9yIChJbnRlZ2VyIGludGVnZXIgOiBsaXN0YSkgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oaW50ZWdlcik7CiAgICAgICAgfQogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQSBtw6lkaWEgZGUgaWRhZGUgw6kgIiArIChzb21hIC8gbGlzdGEuc2l6ZSgpKSk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJBIG1haW9yIGlkYWRlIMOpICIgKyBtYWlvcik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJBIG1lbm9yIGlkYWRlIMOpICIgKyBtZW5vcik7CiAgICB9Cn0=