-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatures
More file actions
45 lines (40 loc) · 1.25 KB
/
Temperatures
File metadata and controls
45 lines (40 loc) · 1.25 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
import java.util.*;
import java.io.*;
import java.math.*;
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int N = in.nextInt(); // the number of temperatures to analyse
in.nextLine();
String TEMPS = in.nextLine(); // the N temperatures expressed as
// integers ranging from -273 to 5526
boolean onlyNegatives = true;
if(N == 0)
System.out.println("0");
else
if(N == 1)
System.out.println(TEMPS);
else
{
String[] number = TEMPS.split("\\s+");
int min = -273;
int [] num = new int[N];
for(int i = 0; i < N; ++i){
num[i] = Integer.parseInt(number[i]);
if(num[i] > 0)
onlyNegatives = false;
}
for (int j = 0; j < N; ++j) {
if (Math.abs(num[j]) < Math.abs(min)) {
min = num[j];
}
}
if (onlyNegatives) {
System.out.println(min);
}
else {
System.out.println(Math.abs(min));
}
}
}
}