So I'm just a bit confused on why my loops weren't successful in their implementation.
1. I tried running a while loop for the keyboard input:
while (true){
if (reader.readLine() == null){
break;
}
list.add(reader.readLine());
}
but it was only returning every other input (grandmother, mother, daughter, dog, car) while the for loop returned them all (grandfather, grandmother, father, mother, son, daughter, cat, dog, program, car)for (int i = 0; i < 10; i++){
list.add(reader.readLine());
}
2. On the topic of the above while loop, how should I be implementing the following boolean to not get a "null pointer exception?": if (reader.readLine().isEmpty())
as this wasn't a problem with if (reader.readLine() == null)
3. In the doublesValue method, I tried adding a value to a new array list based on the index of the value in the list being passed to it. However, it would only work on the first index and not the rest: (i.e. grandfather, grandfather, grandmother, father, ..., grandmother, father, etc...ArrayList<String> newList = new ArrayList<String>();
for (String str : list){
newList.add(str);
}
for (int i = 0; i < list.size(); i++){
newList.add(i+1, list.get(i));
}
Thanks!