Running the program with the inputs is giving the correct answer but does not satisfy the conditions
package com.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.*;
/*
Shortest or longest
1. Create a list of strings.
2. Add 10 strings from the keyboard.
3. Find out which string occurs earlier in the list: the shortest or the longest.
If several strings are shortest or longest, then consider the very first such string encountered.
4. Display the string described in Step 3. One string should be displayed.
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
int max = 0;
int min = 0;
int a = 0;
int b = 0;
Scanner sc = new Scanner(System.in);
ArrayList<String> arl = new ArrayList<String>();
for (int i =0; i<10; i++) {
String readStr = sc.nextLine();
arl.add(readStr);
if (max >= arl.get(i).length()) {
max = arl.get(i).length();
}
if (min <= arl.get(i).length()) {
min = arl.get(i).length();
}
}
for (int i=0; i<10; i++) {
if (arl.get(i).length() == max) {
a = i;
}
if (arl.get(i).length() == min) {
b = i;
}
}
if (a < b) {
System.out.println(arl.get(a));
}
else
System.out.println(arl.get(b));
}
}