My program seems to run correctly, but it is not satisfying the conditions. Help needed!
package com.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Shortest or longest
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
ArrayList<String> list = new ArrayList<String>();
String s;
int sshort=0;
int sLong = 0;
int indexs = 0;
int indexl = 0;
String shorts = null;
String slongs = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
s = reader.readLine();
list.add(s);
}
sshort = list.get(0).length();
for (int i = 0; i < 10; i++) {
if(sLong < list.get(i).length())
sLong = list.get(i).length();
if (sshort < list.get(i).length())
sshort = sshort;
else
sshort = list.get(i).length();
}
System.out.println(sshort);
System.out.println(sLong);
for(int i = 0; i<10; i++){
if(sshort == list.get(i).length())
shorts = list.get(i);
indexs = i;
break;
}
for(int i = 0; i<10; i++){
if(sLong == list.get(i).length()){
slongs = list.get(i);
indexl = i;
break;
}
}
if (indexs < indexl)
System.out.println(shorts);
else
System.out.println(slongs);
}
}