Code:
/*
* 22. Write a Java class called DestroyAllOccurrences, which defines a main() method that asks the user to enter
* two Strings superString and subString, and displays a new String consisting of all characters in superString
* with all occurrences of subString deleted. You MUST NOT use any of the methods defined in the String class
* other than charAt() and length().
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author javapenguin
*/
public class DestroyAllOccurrences {
public static void main(String[] args) {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String superString = new String();
String subString = new String();
System.out.println("Please enter a super string: ");
try {
superString = input.readLine();
} catch (IOException ex) {
System.err.println(ex);
}
System.out.println("Please enter a sub string: ");
try {
subString = input.readLine();
} catch (IOException ex) {
System.err.println(ex);
}
String newString = "";
boolean found = true;
for (int i = 0; i < superString.length(); i++) {
found = false;
for (int j = 0; j < subString.length(); j++) {
if (superString.charAt(i) == subString.charAt(j)) found = true;
}
if (!found) {
newString = newString+superString.charAt(i);
}
}
System.out.println("New String > "+newString);
}
}