Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class CategorizeStrings
  4. {
  5. public static void main(String[] args)
  6. {
  7. final int MAX = 20;
  8. final int CUTOFF = 10;
  9. final String QUIT = "ZZZ";
  10. String entry = "";
  11. int shortSub = 0;
  12. int longSub = 0;
  13. Scanner input = new Scanner(System.in);
  14. String[] longStrings = new String[MAX];
  15. String[] shortStrings = new String[MAX];
  16.  
  17.  
  18. while ((shortSub + longSub) < MAX && !entry.equalsIgnoreCase(QUIT))
  19. {
  20.  
  21. System.out.print("Enter a word or character (or ZZZ to quit): ");
  22.  
  23. entry = input.nextLine();
  24.  
  25. if (!entry.equalsIgnoreCase(QUIT))
  26. {
  27.  
  28. if (entry.length() >CUTOFF)
  29. {
  30.  
  31. longStrings[longSub] = entry;
  32.  
  33. longSub++;
  34. } else
  35. {
  36.  
  37. shortStrings[shortSub] = entry;
  38. shortSub++;
  39. }
  40.  
  41. }
  42. }
  43.  
  44.  
  45. System.out
  46. .print("Which list do you want to display? (S for short, L for long): ");
  47. entry = input.nextLine();
  48.  
  49. if (entry.equalsIgnoreCase("S"))
  50. {
  51.  
  52. if (shortSub == 0)
  53. {
  54. System.out.println("The list is empty");
  55. } else
  56. {
  57. System.out.println("Short List: ");
  58. for (int i = 0; i < shortSub; i++) {
  59. System.out.println(shortStrings[i]);
  60. }
  61. }
  62. } else if (entry.equalsIgnoreCase("L"))
  63. {
  64. if (longSub == 0) {
  65. System.out.println("The list is empty");
  66. } else
  67. {
  68. System.out.println("Long List: ");
  69. for (int i = 0; i < longSub; i++)
  70. {
  71. System.out.println(longStrings[i]);
  72. }
  73. }
  74. }
  75. input.close();
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement