Hello I would like to report a bug in task0708. It seems that verification is broken.
After program reads from input, it takes first string from list as longest and stores it in list of max strings, enters loop at second position. If next string is longer, max list resets and next string gets stored in it. If length is equal, it gets stored w/o reset.
At the end it prints content of max list in loop.
Please look into it.
Ps. Using interface instead of class reference variables should not cause verification to fail.
Some inputs:
father
mot
sonnie
pro
catzie
package com.codegym.task.task07.task0708;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Longest string
*/
public class Solution {
private static ArrayList<String> strings = new ArrayList();
public static void main(String[] args) throws Exception {
//write your code here
Scanner scanner = new Scanner(System.in);
int x = 5;
//int i=0;
while(x>0) {
String s = scanner.nextLine();
strings.add(s);
x--;
}
ArrayList<String> maxList = new ArrayList();
maxList.add(strings.get(0));
for(int i= 1;i<strings.size();i++) {
String s = strings.get(i);
String maxString = maxList.get(maxList.size()-1);
if(s.length()>maxString.length()) {
maxList.clear();
maxList.add(s);
}
else if(s.length()==maxString.length()) {
maxList.add(s);
}
}
System.out.println();
for(int j= 0;j<maxList.size();j++) {
System.out.println(maxList.get(j));
}
}
}