Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- public class _04_SmallestOfThreeNumbers {
- public static void main(String[] args) {
- ArrayList<Double> arrayOfDoubles = new ArrayList<Double>();
- Scanner scanner = new Scanner(System.in);
- for (int i = 0; i < 3; i++) {
- arrayOfDoubles.add(scanner.nextDouble());
- }
- double smallestNumber = Collections.min(arrayOfDoubles);
- // Use this line in order to format the double. Using it, the result will be always in correct format.
- // For example, the whole number -5, which is double, without this formatter it will be printed on the console as - 5.0.
- // If the number is -1.1, it will be printed in a correct format.
- DecimalFormat format = new DecimalFormat();
- System.out.println(format.format(smallestNumber));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement