I am trying to read line by line from the file, then compare numbers in that file.
I am unsure why the program is not executing past the if statement, since my first two numbers in the file are as follows:
1
3
6
4
I am expecting increased value to go up, but it doesn't even hit that point.
public static void numComparison() throws IOException, NumberFormatException {
BufferedReader bufferedReader = new BufferedReader(new FileReader("/Users/WorkAcc/Desktop/file.txt"));
String lines;
LinkedList<Integer> list = new LinkedList<Integer>();
int increased = 0;
while ((lines = bufferedReader.readLine()) != null){
list.add(Integer.parseInt(lines));
}
for (int i = 0; i<=list.size(); i++)
if (list.get(i) < list.get(i++)){
increased++;
}
else{
continue;
}
}
list.get(i++)does?i++issue raised by Scott, yourforloop is setup to dolist.get()beyond the end of your list.