RahulShaw

Race 2

Jan 28th, 2021
583
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.rahulshaw;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.Scanner;
  6.  
  7. public class Race {
  8.    
  9.     public static void main(String args[]) {
  10.  
  11.         ArrayList<Float> distance = new ArrayList<Float>();
  12.         Scanner sc = new Scanner(System.in);
  13.         ArrayList<Float> distance1 = new ArrayList<Float>();
  14.  
  15.         System.out.print("Enter the distance\nEnter value, Q to quit: ");
  16.        
  17.         while (sc.hasNextLine()) {
  18.             String input = sc.nextLine();
  19.             if (input.equalsIgnoreCase("Q")) {
  20.                 break;
  21.             } else {
  22.                 float input1 = Float.parseFloat(input);
  23.                 distance.add(input1);
  24.             }
  25.         }
  26.  
  27.         Collections.sort(distance);
  28.  
  29.         for (int i = distance.size() - 1; i >= 0; i--) {
  30.             if (distance.get(i) < 42.195f) {
  31.                 distance1.add(distance.get(i));
  32.             }
  33.         }
  34.  
  35.         System.out.println(distance1.subList(0, 3));
  36.  
  37.     }
  38. }
  39.  
RAW Paste Data