이런 걸 만들 겁니다.
Document Search
-------start-------
Enter document path: shakespeare.txt
Enter word: foolish
foolish occurs 81 times
(line 2641) Dissuade one foolish heart from serving thee,
(line 5317) heed of the allurement of one Count Rousillon, a foolish idle
(line 8024) CLEOPATRA. For the most part, too, they are foolish that are so.
(line 11091) To bring again these foolish runaways. Exeunt
(line 12265) You foolish shepherd, wherefore do you follow her,
(line 12467) being taken with the cramp, was drown'd; and the foolish
...
Enter document path: shakespeare.txt
Enter word: congratulations
Nothing found... :(
Enter document path: shakespeare.txt
Enter word: quit-word
Enter document path: quit-path
-------quit-------
public static void main(String[] args){
String str = "You will pay for this foolish behavior.";
System.out.println("foolish index: ");
/*
* 코드를 채우시오.
*/
}
출력시 콘솔창
foolish index: 22
public static void main(String[] args){
String str = "You will pay for this foolish behavior.";
System.out.println(str);
/*
* 코드를 채우시오.
*/
}
출력시 콘솔창
You will pay for this foolish behavior.
*******
shakespeare.txt
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Scanner;
public static void main(String[] args){
/*
*......
*......
*......
*/
}
실행시 콘솔창은 아래와 같다. 여기서 shakespeare.txt와 foolish는 키보드를 통해 입력한 문자열이다.
Document Search
-------start-------
Enter document path: shakespeare.txt
Enter word: foolish
foolish occurs 81 times
(line 2641) Dissuade one foolish heart from serving thee,
(line 5317) heed of the allurement of one Count Rousillon, a foolish idle
(line 8024) CLEOPATRA. For the most part, too, they are foolish that are so.
(line 11091) To bring again these foolish runaways. Exeunt
(line 12265) You foolish shepherd, wherefore do you follow her,
(line 12467) being taken with the cramp, was drown'd; and the foolish
...
Enter document path: shakespeare.txt
Enter word: congratulations
Nothing found... :(
Enter document path: shakespeare.txt
Enter word: quit-word
Enter document path: quit-path
-------quit-------
기존의 라이브러리보다 쓰기가 훨씬 쉽다.
List<String> data;
try {
data = Files.readAllLines(Paths.get(dataPath));
} catch(IOException ex) {
throw new RuntimeException(ex);
}
String data;
try {
data = new String(Files.readAllBytes(Paths.get(dataPath)));
} catch(IOException ex) {
throw new RuntimeException(ex);
}
String strWithoutPunctuation = originalStr.replace("[^\\w\\s]", "");
Arrays.sort(Object[] a) 를 사용.
HashSet<Integer> set = ...;
Integer[] sorted = new Integer[set.size()];
set.toArray(sorted);
Arrays.sort(sorted);
for (int n : sorted) System.out.println(n);
Enter document path: shakespeare.txt
Enter word: foolish
foolish occurs in 81 lines
(line 2641) Dissuade one foolish heart from serving thee,
*******
(line 5317) heed of the allurement of one Count Rousillon, a foolish idle
*******
(line 8024) CLEOPATRA. For the most part, too, they are foolish that are so.
*******
(line 11091) To bring again these foolish runaways. Exeunt
*******
(line 12265) You foolish shepherd, wherefore do you follow her,
*******
(line 12467) being taken with the cramp, was drown'd; and the foolish
*******