Created
September 29, 2014 07:01
-
-
Save AIRAT1/3db8a977997e229d0828 to your computer and use it in GitHub Desktop.
This file contains 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
package com.javarush.test.level19.lesson05.task02; | |
/* Считаем слово | |
Считать с консоли имя файла. | |
Вывести в консоль количество слов "world", которые встречаются в файле. | |
Закрыть поток ввода. | |
*/ | |
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class Solution { | |
public static void main(String[] args) throws IOException | |
{ | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
Scanner scanner = new Scanner(new FileReader(reader.readLine())); | |
ArrayList<String> list = new ArrayList<>(); | |
int count = 0; | |
while (scanner.hasNext()) { | |
list.add(scanner.next()); | |
} | |
char[] chars = list.toString().toCharArray(); | |
//System.out.println(chars); | |
for (int i = 0; i < chars.length - 5; i++) { | |
String s = ""; | |
for (int j = i; j < i+5; j++) { | |
s += chars[j]; | |
} | |
//System.out.println(s); | |
if (s.toLowerCase().equals("world")) count++; | |
} | |
System.out.println(count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment