package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Expressing ourselves more concisely
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
// Populate names from the keyboard
ArrayList<Integer> stringsSize = new ArrayList<>();
ArrayList<String> strings = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<5; i++){
// Adding names to ArrayList strings
strings.add( reader.readLine());
}
for(int i=0; i<5; i++){
// Adding name size to ArrayList stringsSize
stringsSize.add(strings.get(i).length());
}
// Find the longest name
int longest = stringsSize.get(0);
for(int i=1; i<5; i++){
if(stringsSize.get(i)<longest){
longest = stringsSize.get(i);
}
}
// Find out if there are more than one name with the longest size
for(int i=0; i<5; i++){
if(stringsSize.get(i)==longest){
System.out.println(strings.get(i));
}
}
}
}
package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Expressing ourselves more concisely
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
// Populate names from the keyboard
ArrayList<Integer> stringsSize = new ArrayList<>();
ArrayList<String> strings = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<5; i++){
// Adding names to ArrayList strings
strings.add( reader.readLine());
}
for(int i=0; i<5; i++){
// Adding name size to ArrayList stringsSize
stringsSize.add(strings.get(i).length());
}
// Find the longest name
int longest = stringsSize.get(0);
for(int i=1; i<5; i++){
if(stringsSize.get(i)<longest){
longest = stringsSize.get(i);
}
}
// Find out if there are more than one name with the longest size
for(int i=0; i<5; i++){
if(stringsSize.get(i)==longest){
System.out.println(strings.get(i));
}
}
}
}