I feel like the logic in my for loops isn't total crap (although please point out where it's wrong if it is), but clearly I've been staring at my solution for so long that I am missing something obvious.
I noticed the issue before submitting the task, because there is no output whatsoever.
any pointers are greatly appreciated, prepackaged solution code not so much :)
thanks in advance!
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 {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
int min=Integer.MAX_VALUE, max=Integer.MIN_VALUE, longest=0, shortest=0;
String i;
for (int x=0; x<10; x++){
list.add(bf.readLine());//write your code here
}
for (int x=0; x<list.size(); x++){
if (list.get(x).length() < min){
min = list.get(x).length();
shortest = list.indexOf(x);
}
}
for (int x=0; x<list.size(); x++){
if (list.get(x).length() > max){
max = list.get(x).length();
longest = list.indexOf(x);
}
}
if (longest < shortest){
i = list.get(longest);
System.out.println(i);
}
if (shortest < longest){
i = list.get(shortest);
System.out.println(i);
}
}
}