Problem 2 Complexity: Low You have been given a set of n strings in an array. Each string contains one or more words separated by spaces. You have another string called “Search String”. You need to match the search string based on word boundary.

254


import java.util.*;
import java.util.Scanner;
public class Problem2 {

public static void main(String[] args) {
	System.out.println("Enter total String : ");
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	String a[]=new String[n];
	for(int i=0;i<n;i++){
		System.out.print("Enter a String : ");
		a[i]=sc.next();
	}
	System.out.println("Enter String to search : ");
	String sr=sc.next();
	boolean f=false;
	for(int i=0;i<a.length;i++){
		if(a[i].contains(sr)){
			System.out.println("Search Successful : "+a[i]);
			f=true;
		}
	}
	if(! f){
		System.out.println("Search unsuccessful !");
	}

}

}