Advertisement
Guest User

04. The Smallest of 3 Numbers

a guest
Aug 27th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.Scanner;
  5.  
  6. public class _04_SmallestOfThreeNumbers {
  7.     public static void main(String[] args) {
  8.         ArrayList<Double> arrayOfDoubles = new ArrayList<Double>();
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         for (int i = 0; i < 3; i++) {
  12.             arrayOfDoubles.add(scanner.nextDouble());
  13.         }
  14.  
  15.         double smallestNumber = Collections.min(arrayOfDoubles);
  16.  
  17.         // Use this line in order to format the double. Using it, the result will be always in correct format.
  18.         // For example, the whole number -5, which is double, without this formatter it will be printed on the console as - 5.0.
  19.         // If the number is -1.1, it will be printed in a correct format.
  20.         DecimalFormat format = new DecimalFormat();
  21.  
  22.         System.out.println(format.format(smallestNumber));
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement