public static void main(String[] args) throws Exception {
ArrayList<String> strings = new ArrayList<>();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> stringSize = new ArrayList<>();
for(int i=0;i<10;i++){
String s = bufferedReader.readLine();
strings.add(s);
stringSize.add(s.length());
}
Collections.sort(stringSize);
String max = "";
int maxIndex = 0;
String min = "";
int minIndex = 0;
for(String s:strings){
if(s.length()==stringSize.get(0)){
min = s;
minIndex = strings.indexOf(s);
}
if(s.length()==stringSize.get(9)){
max = s;
maxIndex = strings.indexOf(s);
}
}
if(maxIndex>minIndex){
System.out.println(min);
}else {
System.out.println(max);
}
}
package zh.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
/*
最短或最长
*/
public class Solution {
public static void main(String[] args) throws Exception {
//在此编写你的代码
ArrayList<String> strings = new ArrayList<>();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> stringSize = new ArrayList<>();
for(int i=0;i<10;i++){
String s = bufferedReader.readLine();
strings.add(s);
stringSize.add(s.length());
}
Collections.sort(stringSize);
String max = "";
int maxIndex = 0;
String min = "";
int minIndex = 0;
for(String s:strings){
if(s.length()==stringSize.get(0)){
min = s;
minIndex = strings.indexOf(s);
}
if(s.length()==stringSize.get(9)){
max = s;
maxIndex = strings.indexOf(s);
}
}
if(maxIndex>minIndex){
System.out.println(min);
}else {
System.out.println(max);
}
}
}