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: ");
height = sc.nextInt();
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();
}
}
How can I limit words read from scanner to fill the requirements?Currently the while loop doesn't influence scanner at all :/
This is not a homework. I'm trying to create a simple application and then gui for it.