-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVintequatro.java
More file actions
39 lines (33 loc) · 1 KB
/
Copy pathVintequatro.java
File metadata and controls
39 lines (33 loc) · 1 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
package TodosExecicios;
//24. Faça um programa que leia um array de números do usuário até que o usuário insira um
//número negativo. Em seguida, imprima a média dos números lidos e quantos números foram pares.
import java.util.ArrayList;
import java.util.Scanner;
public class Vintequatro {
public static void main (String []args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> num = new ArrayList<>();
int soma = 0;
int pares = 0;
System.out.println("Digite um número negativo para encerrar. ");
System.out.println("Informe os números: ");
while(true) {
Integer numeros = sc.nextInt();
if (numeros< 0){
break;
}
num.add(numeros);
soma+=numeros;
if (numeros%2==0) {
pares++;
}
}
if(!num.isEmpty()) {
double m = (double) soma/num.size();
System.out.println("A média dos números inseridos é: " + m + "\nE " + pares + " números são pares.");
}else {
System.out.println("Nenhum número foi inserido.");
}
sc.close();
}
}