It seems a rather easy exercise hence my confusion that I get very strange output. It returns a '4'. And it should be '1'.
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<String>();//declare a string list and initialize it
for(int i = 0; i < 10; i++)//iterate over the loop to
{
String s = reader.readLine();//reads 10 Strings from keyboard
list.add(s);
}
for(int i = 0; i < 9; i++){
if(list.get(i).length() < (list.get(i+1).length())){//how to find the length of an individual string in an ArrayList?
System.out.println(i);
break;// if the length of the next string is shorter than previous return indexnumber otherwise don't return anything
}
//else{}//if it is ordered in order by increasing length don't do anything
}
}
}