I tested it with various lists, and I always get the correct result.
Does anyone see a problem in the code?
package com.codegym.task.task07.task0718;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Checking the order
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
String s = reader.readLine();
list.add(s);
}
int len = list.get(0).length();
for (int i = 1; i < list.size() - 1;) {
if (len <= list.get(i).length()) {
len = list.get(i).length();
i++;
} else {
System.out.println(i);
break;
}
}
}
}