Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public class Main {
  2.  
  3. protected static ArrayList<String> Letter = new ArrayList<String>();
  4. private static String[] letters;
  5. private static String l;
  6.  
  7. public static void main(String args[]) {
  8.  
  9. System.out.println("Welcome to the Word Generator");
  10. System.out.println("Please enter a comma separated list of letters ranging from 2-10 characters");
  11.  
  12. Scanner input = new Scanner(System.in);
  13. l = input.nextLine();
  14. letters = l.split(",");
  15. //while the input does not meet constraints, keep asking to reenter input
  16. while (letters.length <= 1 || letters.length >= 9 || checkFormat(letters) == false) {
  17. letters = null;
  18. l = null;
  19. System.out.println("Error: The list must be between 2 and 10 characters long");
  20. System.out.println("Please reenter your list:");
  21. l = input.nextLine();
  22. letters = l.split(",");
  23. }
  24.  
  25. //if input is good...
  26. if (letters.length >= 2 && letters.length <= 10) {
  27. //fill ArrayList with elements of user input
  28. for (int i = 0; i < Main.letters.length; i++) {
  29. Letter.add(letters[i]);
  30. }
  31. //close input
  32. input.close();
  33. }
  34. System.out.println(Letter);
  35. }
  36.  
  37. public static boolean checkFormat(String[] list) {
  38. for (int i = 0; i < l.length(); i++) {
  39. if (list[i].length() > 1) {
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement