filling array gradually with data from user
- by neville
I'm trying to fill an array with words inputted by user. Each word must be one letter longer than previous and one letter shorter than next one. Their length is equal to table row index, counting from 2. Words will finally create a one sided pyramid, like :
A
AB
ABC
ABCD
Scanner sc = new Scanner(System.in);
System.out.println("Give the height of array: ");
String[] words = new String[height];
for(int i=2; i<height+2; i++){
System.out.println("Give word with "+i+" letters.");
words[i-2] = sc.next();
while( words[i-2].length()>i-2 || words[i-2].length()<words[i-3].length() ){
words[i-2] = sc.next();
}
}
Currently the while loop doesn't influence scanner at all :/