Advertisement
Vladkoheca

Search.java

Dec 3rd, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(sc.nextLine());
  9.         String randWord = sc.nextLine();
  10.         ArrayList <String> sentences = new ArrayList<>();
  11.         for (int i = 0; i < n; i++) {
  12.             sentences.add(sc.nextLine());
  13.         }
  14.         System.out.println(sentences);
  15.  
  16.         ArrayList <String> newSentences = new ArrayList<>();
  17.  
  18.         for (String sentence : sentences) {
  19.             if (sentence.contains(randWord)) {
  20.                 newSentences.add(sentence);
  21.             }
  22.         }
  23.         System.out.println(newSentences);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement