Hello
I succes all the conditions of the screen output mission, but my exercise is not validated:
package fr.codegym.task.task07.task0717;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Duplication de mots
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader lecteur = new BufferedReader(new InputStreamReader(System.in));
ArrayList <String> liste = new ArrayList<String>();
while (true){
String s = lecteur.readLine();
if (s.isEmpty()) break;
liste.add(s);
}
ArrayList<String> resultat = dupliquerValeurs(liste);
for (String s : resultat){
System.out.println(s);
}
}
public static ArrayList<String> dupliquerValeurs(ArrayList<String> liste) {
for (int i = 0; i< liste.size(); ){
String s = liste.get(i);
liste.add(i+1, s);
i+=2;
}
return liste;
}
}
in screen output its good :
grand-père
grand-père
grand-mère
grand-mère
père
père
mère
mère
fils
fils
fille
fille
chat
chat
chien
chien
programme
programme
voiture
voiture
mais code gym ne me valide pas la condition :
but code gym don't accept the last condition :
Displays the resulting list, each item on a new line.
why ??
why the last condition is not accepted ?
Discussion en cours
Commentaires (4)
- Populaires
- Nouveau
- Anciennes
Tu dois être connecté(e) pour laisser un commentaire
Marie - Elise Frapier Java Developer chez douanes francaise
14 octobre 2021, 07:28
I had 10 lines in input, it's not the problem
0
Lisa
14 octobre 2021, 08:25
admitted, you may have 10 lines in your input but for that you must enter an empty line after the 10th line.
If I test your code I can eg. enter infinite lines or, if I enter an empty line as second line I have a list with a size of 1. Third line an empty line -> list size of 2. There are infinite possibilities to make the size requirement fail but only one to make it pass. That makes it a problem in my book. If you see that differently... ok. Still, without other ideas I'd try my previous suggestion and see what happens before completely ruling this out as a problem.
+1
Marie - Elise Frapier Java Developer chez douanes francaise
14 octobre 2021, 14:46
ok I understand, thank you very much
0
Lisa
12 octobre 2021, 10:36
I do not now how it is in the french version of the course but in the german one CG asks for exactly 10 lines you should input and not till an empty line is entered. Address that first before looking for further problems.
+1