Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #1402

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

done #1402

Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/main/java/core/basesyntax/FileWork.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
package core.basesyntax;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class FileWork {

public String[] readFromFile(String fileName) {
//write your code here
return null;
String[] finalWords;
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName))) {
String result = bufferedReader.readLine();
System.out.println(result);
String[] words = result.split("\\W+");
int count = 0;
for (String s : words) {
String first = s.toLowerCase().substring(0,1);
if (first.equals("w")) {
count++;
}
}
finalWords = new String[count];
count = 0;
ArrayList<String> list = new ArrayList<>();
for (String s : words) {
System.out.println(s);
String first = s.toLowerCase().substring(0,1);
if (first.equals("w")) {
list.add(s.toLowerCase());
}
}
Collections.sort(list);
System.out.println(list);
for (String s : list) {
System.out.println(s);
finalWords[count] = s;
count++;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return finalWords;
}
}
Loading