Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Curs19;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Ex2Filter {
- public static String[] lettersMatchIgnoreCase(String[] arrTLC, String key) {
- String[] answear = new String[arrTLC.length];
- int numElem = 0;
- char[] ch = new char[key.length()];
- ch = key.toCharArray();
- for (int i = 0; i < arrTLC.length; i++) {
- for (int j = 0; j < arrTLC[i].length(); j++) {
- for (int k = 0; k < ch.length; k++) {
- if (ch[k] == arrTLC[i].charAt(j) && j == k) {
- answear[numElem] = arrTLC[i];
- numElem++;
- break;
- }
- }
- }
- }
- answear = Arrays.copyOf(answear, numElem);
- return answear;
- }
- public static void printArray(String[] answear) {
- for (int i = 0; i < answear.length; i++) {
- System.out.print(answear[i] + " ");
- }
- }
- public static String[] convertToLowerCase(String[] array) {
- String[] answear = new String[array.length];
- for (int i = 0; i < array.length; i++) {
- answear[i] = array[i].toLowerCase();
- }
- return answear;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] array = new String[2];
- String stopStr = "stop";
- int numOfStr = 0;
- System.out.println("Enter the strings:");
- String s = sc.next();
- while (!s.equals(stopStr)) {
- array[numOfStr] = s;
- numOfStr++;
- if (numOfStr == array.length) {
- array = Arrays.copyOf(array, array.length * 2);
- }
- s = sc.next();
- }
- array = Arrays.copyOf(array, numOfStr);
- System.out.println("Enter the key word:");
- String key = sc.next();
- String[] arrTLC = convertToLowerCase(array);
- String[] answear = lettersMatchIgnoreCase(arrTLC, key);
- printArray(answear);
- //System.out.println();
- //removeDuplicate(answear);
- //Exemplu:
- //strings: border ant drop Fly racoon class Plane
- //key: plot
- //RETURN: ["drop", "Fly", "class", "Plane"]
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement