montimaj

String Check

Dec 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. class CheckString {
  4.     public static void main(String args[]) {
  5.         try {
  6.             System.out.print("Enter text: ");
  7.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  8.             String text = br.readLine();
  9.             System.out.print("Enter string to be searched: ");                      
  10.             String pattern = br.readLine();
  11.             if(text.contains(pattern)) {
  12.                 System.out.println(pattern + " found");
  13.             } else {
  14.                 System.out.println(pattern + " not found");
  15.             }
  16.         } catch(IOException e) { e.printStackTrace(); }
  17.     }
  18. }
Add Comment
Please, Sign In to add comment