Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- protected static ArrayList<String> Letter = new ArrayList<String>();
- private static String[] letters;
- private static String l;
- public static void main(String args[]) {
- System.out.println("Welcome to the Word Generator");
- System.out.println("Please enter a comma separated list of letters ranging from 2-10 characters");
- Scanner input = new Scanner(System.in);
- l = input.nextLine();
- letters = l.split(",");
- //while the input does not meet constraints, keep asking to reenter input
- while (letters.length <= 1 || letters.length >= 9 || checkFormat(letters) == false) {
- letters = null;
- l = null;
- System.out.println("Error: The list must be between 2 and 10 characters long");
- System.out.println("Please reenter your list:");
- l = input.nextLine();
- letters = l.split(",");
- }
- //if input is good...
- if (letters.length >= 2 && letters.length <= 10) {
- //fill ArrayList with elements of user input
- for (int i = 0; i < Main.letters.length; i++) {
- Letter.add(letters[i]);
- }
- //close input
- input.close();
- }
- System.out.println(Letter);
- }
- public static boolean checkFormat(String[] list) {
- for (int i = 0; i < l.length(); i++) {
- if (list[i].length() > 1) {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement