SHARE
TWEET

Untitled

a guest Feb 22nd, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.image.AreaAveragingScaleFilter;
  2. import java.util.*;
  3.  
  4. public class NamesList {
  5.     public static void main(String[] args) {
  6.         Scanner scanner= new Scanner(System.in);
  7.         String str ;
  8.         ArrayList<String> names=new ArrayList<>();
  9.  
  10.         while(true){
  11.             System.out.println("Enter Name: ");
  12.             str = scanner.nextLine();
  13.             names.add(str);
  14.             if(str.contains(".")){
  15.                 names.remove(".");
  16.                 break;
  17.             }
  18.         }
  19.         System.out.println(names);
  20.         if(names.size()<4) {
  21.             System.out.println("There is no a 5th name!");
  22.         }else{
  23.             System.out.println( "The 5th name on the list is: "+ names.get(4));
  24.         }
  25.         Collections.sort(names);
  26.         System.out.println(names);
  27.  
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top