Skip to content

Instantly share code, notes, and snippets.

@nherbaut
Created September 28, 2023 12:06
Show Gist options
  • Select an option

  • Save nherbaut/91f68c0e79f4b6c5cfede0b43006040f to your computer and use it in GitHub Desktop.

Select an option

Save nherbaut/91f68c0e79f4b6c5cfede0b43006040f to your computer and use it in GitHub Desktop.
L2.2.4 Les mots
elephant
monkey

avec ce fichier words.txt, quelle sera la sortie de ce programme?

import java.util.Map;
import java.util.HashMap;
public class HelloWorld
{
public static void main(String args[]){
FileResource f = new FileResource("words.txt");
for (String g : f.lines()) {
if (g.length() > 5) {
System.out.println(g);
}
}
}
static class FileResource{
private final static Map<String,String> content;
static {
content=new HashMap<>();
content.put("words.txt","cat\nelephant\nmonkey\ntiger\nlion");
}
private final String resource;
public FileResource(String ref){
resource=content.get(ref);
}
public String[] lines(){
return resource.split("\n");
}
}
}
@nherbaut
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment