OneCompiler

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.

306
 
 
import java.util.Scanner;

public class Problem_02 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		String[] strarr= {"Cecilio Johnes",
				"Cordell Acott",
				"Curtice Bleue",
				"Dalis Menary",
				"Emanuele Barstock",
				"Emmy Bradane",
				"Gian Cossington",
				"Jamaal Danilevich",
				"Kerri Wilce",
				"Liuka Cowern",
				"Merrel Cornuau",
				"Marena Appleton",
				"Marlee Stobo",
				"Rochette Brew",
				"Rudyard Abbate",
				"Sharona Climo",
				"Shirlee Titcumb",
				"Taite Joriot",
				"Taite Huntriss",
			    "Zach Simchenko"};
		
		Scanner sc = new Scanner(System.in);
	    System.out.println("Enter string expecting as output : ");
	    String s = sc.next();
		
	    String[] s1=new String[2];
		
		
	    for(int i=0;i<strarr.length;i++) {
			s1= strarr[i].split(" ");
			for(int j=0;j<s1.length;j++) {
							
				if(s.equalsIgnoreCase(s1[j].substring(0, 1))) {
					for(String x:s1)
					System.out.print(x+" ");
					System.out.println();
				}
				else if(s.equalsIgnoreCase(s1[j].substring(0, 2))) {
					for(String x:s1)
						System.out.print(x+" ");
						System.out.println();
				}
				
			}
		}

}

}