Advertisement
elsemTim

java compare Double

Jul 29th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Test {
  4.  
  5.     public void main() {
  6.         ArrayList<Double> arrayList = new ArrayList<>();
  7.         arrayList.add(1.22);
  8.         arrayList.add(2.3333);
  9.         arrayList.add(4.3453);
  10.         arrayList.add(-13.45);
  11.         Double minValue = Double.MAX_VALUE;
  12.         Double maxValue = Double.MIN_VALUE;
  13.         for (Double element : arrayList) {
  14.             if (Double.compare(element, minValue) < 0) {
  15.                 minValue = element;
  16.             }
  17.             if (Double.compare(element, maxValue) > 0) {
  18.                 maxValue = element;
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement