Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.*;
  3.  
  4. public class CategorizeStrings {
  5. public static void main(String[] args) {
  6. ArrayList<String> shortStrings = new ArrayList<String>();
  7. ArrayList<String> longStrings = new ArrayList<String>();
  8. Scanner sc = new Scanner(System.in);
  9. String line = "";
  10. System.out.println("Enter a character or word (or ZZZ to quit)");
  11. line = sc.nextLine();
  12. int count = 0;
  13. while (!line.equalsIgnoreCase("ZZZ") && count < 20) {
  14. count++;
  15. if (line.length() <= 10)
  16. shortStrings.add(line);
  17. else
  18. longStrings.add(line);
  19. System.out.println("Enter String (zzz) to exit");
  20. line = sc.nextLine();
  21. }
  22. System.out.println("Which list you want to display? Enter S for Short or L Long");>
  23. String ch = sc.nextLine();
  24. if (ch.equalsIgnoreCase("S")) {
  25. if (shortStrings.size() == 0)
  26. System.out.println("The list is empty");
  27. else
  28. System.out.println(shortStrings);
  29. }
  30. if (ch.equalsIgnoreCase("L")) {
  31. if (longStrings.size() == 0)
  32. System.out.println("The list is empty");
  33. else
  34. System.out.println(longStrings);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement