First, let me just mention that the code I type here keeps getting changed when it shows in the preview. So it's possible that what you see isn't the code I typed. I'm going to check what it posts as soon as I hit publish and update with a comment if it's not my code. I'm not sure why this keeps happening. Anyway, I have this code and for every combination of strings I have entered, it always produces the correct result. But when validating, it fails on the last condition.
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 {
ArrayList<String> strings = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++)
{
strings.add(reader.readLine());
}
for(int i = 0; i < strings.size()-2; i++)
{
// Also tried the following conditional using just less-than, same result. Task conditions are not clear on whether or not two strings of same length constitute
// "violating this order" or not
if(strings.get(i+1).length() <= strings.get(i).length())
{
System.out.println((i+1));
break;
}
}
}
}
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 {
ArrayList<String> strings = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++)
{
strings.add(reader.readLine());
}
for(int i = 0; i < strings.size()-2; i++)
{
if(strings.get(i+1).length() < strings.get(i).length())
{
System.out.println((i+1));
break;
}
}
}
}