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> listString = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
listString.add(reader.readLine());
}
int shortest = listString.get(0).length();
int postitionShort = 0;
int positionLong = 0;
boolean firstShort = false;
boolean firstLong = false;
boolean found = false;
int longest = listString.get(listString.size() - 1).length();
for (int i = 0; i < listString.size(); i++) {
if (shortest > listString.get(i).length()) {
shortest = listString.get(i).length();
postitionShort = i;
}
if (longest < listString.get(i).length()) {
longest = listString.get(i).length();
positionLong = i;
}
}
for (int i = 0; i < listString.size(); i++) {
if (i == positionLong) {
firstLong = true;
System.out.println(listString.get(i));
break;
} else if (i == postitionShort) {
firstShort = true;
System.out.println(listString.get(i));
break;
}
}
}
}
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> listString = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
listString.add(reader.readLine());
}
int shortest = listString.get(0).length();
int postitionShort = 0;
int positionLong = 0;
boolean firstShort = false;
boolean firstLong = false;
boolean found = false;
int longest = listString.get(listString.size() - 1).length();
for (int i = 0; i < listString.size(); i++) {
if (shortest > listString.get(i).length()) {
shortest = listString.get(i).length();
postitionShort = i;
}
if (longest < listString.get(i).length()) {
longest = listString.get(i).length();
positionLong = i;
}
}
for (int i = 0; i < listString.size(); i++) {
if (found == false) {
if (i == positionLong) {
found = true;
System.out.println(listString.get(i));
} else if (i == postitionShort) {
found = true;
System.out.println(listString.get(i));
}
}
}
}
}