-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutlier.java
57 lines (48 loc) · 1.19 KB
/
Outlier.java
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
import java.util.*;
public class Outlier {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[3];
for (int i = 0; i < arr.length; i++)
{
arr[i] = sc.nextInt();
}
sc.close();
arr = bubbleSort(arr);
if (arr[1] - arr[0] > arr[2] - arr[1])
{
System.out.println(arr[0]);
}
else if (arr[1] - arr[0] == arr[2] - arr[1])
{
System.out.println("NA");
}
else
{
System.out.println(arr[2]);
}
}
public static int[] bubbleSort(int[] arr)
{
int leng = arr.length;
for (int i = 0; i < leng -1; i++)
{
boolean swapped = false;
for (int j = 0; j < leng - i - 1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
swapped = true;
}
}
if (!swapped)
{
break;
}
}
return arr;
}
}