Question: I want to check if my String contains any string from the array that I have created and REMOVE them: JAVA Do not use .replace

I want to check if my String contains any string from the array that I have created and REMOVE them:

JAVA

Do not use .replace or .remove method.

import java.util.Scanner;

public class Sweep { public static String remove(String s1) { String str = ""; String[] str1 = {"so", "do", "the", "re", "as", "are", "and", "or", "?", "!", "(", ")"};

for (int i = 0; i < s1.length(); ++i) { if (s1.substring(s1.length()).equals(str1[i])) str += s1.substring(i); }

str = str.toLowerCase(); //lowercase the entire string return str; } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String s1 = ""; System.out.print("Input: "); s1 = scnr.nextLine();

System.out.println("Output: " + remove(s)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!