Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int closestTemp;
- if(N != 0) {
- String TEMPS = in.nextLine(); // the N temperatures expressed as integers ranging from -273 to 5526
- Scanner tempParse = new Scanner(TEMPS);
- closestTemp = tempParse.nextInt(); // closest temperature
- for(int count = 0; count < N-1; count++) {
- int temp = tempParse.nextInt();
- System.err.println("Temp = " + temp); // print temperature
- if(Math.abs(closestTemp) > Math.abs(temp) ||
- (Math.abs(closestTemp) == Math.abs(temp) && closestTemp < temp)) {
- closestTemp = temp;
- }
- }
- } else {
- closestTemp = 0;
- }
- System.out.println(closestTemp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement