Not able to figure out the issue with code..
Pgm is meant to fnd the minimum of the arraylist..
https://codegym.cc/quests/lectures/questsyntax.level07.lecture06
Code:
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
shortest string
*/
public class Solution {
private static ArrayList<String> strings = new ArrayList<String>();
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i=0; i<5; i++) {
String element = reader.readLine();
strings.add(i, element);
}
int min = 9999;
for(int i=0; i<strings.size();i++) {
if (strings.get(i).length() < min) {
min = strings.get(i).length();
}
}
for (int i=0; i<strings.size();i++) {
if(strings.get(i).length() == min) {
System.out.println(strings.get(i));
}
}
}
}
https://codegym.cc/quests/lectures/questsyntax.level07.lecture06
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Roman Ivanov
19 January 2019, 16:06
What if all of the 5 lines entered are each longer than 9999?
0
ManasaBhattaru
19 January 2019, 20:34
i wanted to gve some value to the variable..
0
Roman Ivanov
19 January 2019, 21:38
So, if you are looking for the shortest string, then assign to this variable the maximum value of int:
But what is the exact number of the task you are trying to solve? 0