Advertisement
dimipan80

Exam 2. Three Largest Numbers

Sep 14th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class _2_ThreeLargestNumbers {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner scan = new Scanner(System.in);
  10.         int count = scan.nextInt();
  11.         scan.nextLine();
  12.  
  13.         BigDecimal[] numbers = new BigDecimal[count];
  14.         for (int i = 0; i < count; i++) {
  15.             String nextLine = scan.nextLine();
  16.             numbers[i] = new BigDecimal(nextLine);
  17.         }
  18.  
  19.         Arrays.sort(numbers);
  20.         for (int i = numbers.length - 1; i > numbers.length - 4 && i >= 0; i--) {
  21.             System.out.println(numbers[i].toPlainString());
  22.         }
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement