-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoze.java
More file actions
37 lines (28 loc) · 910 Bytes
/
Copy pathDoze.java
File metadata and controls
37 lines (28 loc) · 910 Bytes
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
package TodosExecicios;
import java.util.Scanner;
//12.Façaumprogramaqueleiaumarraydenúmerosdousuárioatéqueousuárioinsiraumnúmeronegativo.
//Emseguida,imprimaamédiadosnúmeroslidos.
public class Onze {
public static void main (String []args) {
Scanner sc = new Scanner(System.in);
System.out.println("Informe o tamanho do Array: ");
int tamanho = sc.nextInt();
Integer [] numero = new Integer[tamanho];
int cont = 0;
int num = 0;
int media = 0;
System.out.println("Informe os números do array: ");
System.out.println("Ou digite um número negativo para encerrar. ");
for (int i = 0; i < tamanho; i++) {
numero[i] = sc.nextInt();
if (numero [i] < 0) {
break;
}
media +=numero[i];
cont++;
}
double m = (double) media/cont;
System.out.println("Foram informados " + cont + " números.");
System.out.println("A média dos numeros é: " + m);
}
}