INSTRUCTIONS:
Write an application that accepts any number of String values from a user until they enter zzz or have entered 15 strings, and display them in ascending order (alphabetical order).
Case should be a factor when ordering the values. For example, uppercase 'B' comes before lowercase 'a'.
PROBLEM:
The loop won't stop when I input "zzz"
After filling 15 strings: The console will prompt "Array Index OutOfBoundsException:15
import java.util.*;
public class StringSort2 {
public static void main(String[] args) {
String[] hatdog = new String[15];
Scanner input = new Scanner(System.in);
for (int i = 0; i <= hatdog.length; i++){
String words = input.nextLine();
if(words != "zzz")
hatdog[i] = words;
else if (words == "zzz")
break;
}
Arrays.sort(hatdog);
for(int j=0; j<hatdog.length; j++)
System.out.println(hatdog[j]);
}
}