First, two task pass but can`t print right longest and shortest string. Thank you.
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 {
ArrayList<String> strings = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<10; i++){
String s = reader.readLine();
strings.add(s);
}
int longest = Integer.MIN_VALUE;
int longestIndex = -1;
for(int i=0; i<strings.size(); i++){
int s = strings.get(i).length();
if(s > longest){
longestIndex = i;
longest = s;
}
}
int shortest = Integer.MAX_VALUE;
int shortestIndex = 0;
for(int i=0; i<strings.size(); i++){
int s = strings.get(i).length();
if(s < shortest){
shortestIndex =i ;
shortest = s;
}
}
for(int i=0; i<strings.size(); i++){
String z = strings.get(i);
if(z.length() == shortestIndex || z.length() == longestIndex){
System.out.println(z);
}
}
}
}