- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmode.java
More file actions
Latest commit
27 lines (24 loc) · 604 Bytes
/
Copy pathmode.java
File metadata and controls
27 lines (24 loc) · 604 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
publicclassmode{
publicstaticintfindMode(int[] data) {
intmaxValue = 0;
intmaxCount = 0;
for (inti = 0; i < data.length; i++) {
intcount = 1;
for (intj = i + 1; j < data.length; j++) {
if (data[i] == data[j]) {
count++;
}
}
if (count > maxCount) {
maxCount = count;
maxValue = data[i];
}
}
returnmaxValue;
}
publicstaticvoidmain(String[] args) {
int[] data = {3, 1, 4, 1, 5, 9, 3, 2, 1};
intmode = findMode(data);
System.out.println("The mode of the data is: " + mode);
}
}