Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CategorizeStrings
- {
- public static void main(String[] args)
- {
- final int MAX = 20;
- final int CUTOFF = 10;
- final String QUIT = "ZZZ";
- String entry = "";
- int shortSub = 0;
- int longSub = 0;
- Scanner input = new Scanner(System.in);
- String[] longStrings = new String[MAX];
- String[] shortStrings = new String[MAX];
- while ((shortSub + longSub) < MAX && !entry.equalsIgnoreCase(QUIT))
- {
- System.out.print("Enter a word or character (or ZZZ to quit): ");
- entry = input.nextLine();
- if (!entry.equalsIgnoreCase(QUIT))
- {
- if (entry.length() >CUTOFF)
- {
- longStrings[longSub] = entry;
- longSub++;
- } else
- {
- shortStrings[shortSub] = entry;
- shortSub++;
- }
- }
- }
- System.out
- .print("Which list do you want to display? (S for short, L for long): ");
- entry = input.nextLine();
- if (entry.equalsIgnoreCase("S"))
- {
- if (shortSub == 0)
- {
- System.out.println("The list is empty");
- } else
- {
- System.out.println("Short List: ");
- for (int i = 0; i < shortSub; i++) {
- System.out.println(shortStrings[i]);
- }
- }
- } else if (entry.equalsIgnoreCase("L"))
- {
- if (longSub == 0) {
- System.out.println("The list is empty");
- } else
- {
- System.out.println("Long List: ");
- for (int i = 0; i < longSub; i++)
- {
- System.out.println(longStrings[i]);
- }
- }
- }
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement