This code seems to work I cannot figure out why it is failing.
package com.codegym.task.task07.task0718;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
/*
Checking the order
*/
public class Solution {
public static void main(String[] args) throws IOException {
ArrayList<String> list = new ArrayList<String>();
ArrayList<Integer> temp1 = new ArrayList<Integer>();
ArrayList<Integer> temp2 = new ArrayList<Integer>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//Get 10 input from user
for (int i = 0; i < 10; i++){
list.add(reader.readLine());
}
//Create two lists with the string lengths of each element in list
for (int i = 0; i < list.size(); i++){
int length = list.get(i).length();
temp1.add(length);
temp2.add(length);
}
//Sort a temp array for comparison
Collections.sort(temp2);
//Check if temp arrays are equal
if (temp1.equals(temp2)){
}
else
{
//Check the order of the list against the sorted list(temp2)
for (int i = 0; i < list.size(); i++){
if (list.get(i).length() != temp2.get(i) ){
System.out.println(i);
break;
}
}
}
}
}