Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.*;
- public class CategorizeStrings {
- public static void main(String[] args) {
- ArrayList<String> shortStrings = new ArrayList<String>();
- ArrayList<String> longStrings = new ArrayList<String>();
- Scanner sc = new Scanner(System.in);
- String line = "";
- System.out.println("Enter a character or word (or ZZZ to quit)");
- line = sc.nextLine();
- int count = 0;
- while (!line.equalsIgnoreCase("ZZZ") && count < 20) {
- count++;
- if (line.length() <= 10)
- shortStrings.add(line);
- else
- longStrings.add(line);
- System.out.println("Enter String (zzz) to exit");
- line = sc.nextLine();
- }
- System.out.println("Which list you want to display? Enter S for Short or L Long");>
- String ch = sc.nextLine();
- if (ch.equalsIgnoreCase("S")) {
- if (shortStrings.size() == 0)
- System.out.println("The list is empty");
- else
- System.out.println(shortStrings);
- }
- if (ch.equalsIgnoreCase("L")) {
- if (longStrings.size() == 0)
- System.out.println("The list is empty");
- else
- System.out.println(longStrings);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement