avec ce fichier words.txt, quelle sera la sortie de ce programme?
Created
September 28, 2023 12:06
-
-
Save nherbaut/91f68c0e79f4b6c5cfede0b43006040f to your computer and use it in GitHub Desktop.
L2.2.4 Les mots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| elephant | |
| monkey |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
execute me on https://java.miage.dev/?gistId=91f68c0e79f4b6c5cfede0b43006040f