Advertisement
ibragimova_mariam

Поиск

May 10th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) throws IOException {
  9.         String encoding = "UTF-8";
  10.        
  11.         Scanner sc = new Scanner(System.in);
  12.         System.out.println("Введите фамилии через пробел: ");
  13.         String input = sc.nextLine();
  14.  
  15.         Set<String> lastNames = new HashSet<>(Arrays.asList(input.split(" ")));
  16.        
  17.         System.out.println("Найденные совпадения: ");
  18.         try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/com/company/input.txt"), encoding))) {
  19.             for (String line; (line = reader.readLine()) != null; ) {
  20.                 int separator = line.indexOf(' ');
  21.                 String lastName = line.substring(0, separator);
  22.  
  23.                 if (lastNames.contains(lastName)) {
  24.                     System.out.println(line);
  25.                 }
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement