-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercicioVetor3
More file actions
79 lines (57 loc) · 1.95 KB
/
Copy pathExercicioVetor3
File metadata and controls
79 lines (57 loc) · 1.95 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package exerciciovetor3;
import java.util.Scanner;
import java.util.Arrays;
public class ExercicioVetor3 {
public static void main(String[] args) {
int vetor[] = new int[10];
int vetorEle[] = new int[10];
int vetorFreq[] = new int[10];
Scanner lt = new Scanner(System.in);
Arrays.sort(vetor);
int media=0, valor=0, pos=0, maiorFreq=0;
float mediana=0;
String moda="Moda:( ";
for (int i = 0; i < 10; i++) {
System.out.println("Informe um valor ");
valor = lt.nextInt();
vetor[i] = valor;
vetorEle[i]=-1;
vetorFreq[i]=-1;
}
vetorEle[0]=vetor[0];
vetorFreq[0]=1;
for (int i = 1; i < vetor.length; i++) {
if(vetor[i] != vetor[(i-1)]){
pos++;
vetorEle[pos] = vetor[i];
vetorFreq[pos] = 1;
} else{
vetorFreq[pos]++;
}
}
for (int i = 0; i < 10; i++) {
if(vetorFreq[i]>maiorFreq){
maiorFreq = vetorFreq[i];
}
}
for (int i = 0; i < 10; i++) {
if(vetorFreq[i] == maiorFreq){
moda = moda+vetorEle[i]+", ";
}
}
for (int i = 0; i < 10; i++) {
media += vetor[i];
}
for (int i = 0; i < 10; i++) {
mediana = (vetor[4]+vetor[5])/2f;
}
int index = moda.lastIndexOf(",");
moda = moda.substring(0, index) + ')';
int soma = media;
media = media/10;
System.out.println("\nA media eh: " + media);
System.out.format("\nA mediana eh : %.1f\n", mediana);
System.out.println("\n" + moda);
System.out.println("\nA soma eh: " + soma);
}
}