Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- String encoding = "UTF-8";
- Scanner sc = new Scanner(System.in);
- System.out.println("Введите фамилии через пробел: ");
- String input = sc.nextLine();
- Set<String> lastNames = new HashSet<>(Arrays.asList(input.split(" ")));
- System.out.println("Найденные совпадения: ");
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/com/company/input.txt"), encoding))) {
- for (String line; (line = reader.readLine()) != null; ) {
- int separator = line.indexOf(' ');
- String lastName = line.substring(0, separator);
- if (lastNames.contains(lastName)) {
- System.out.println(line);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement