forked from task032015/stringProblem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringProblem1.java
More file actions
38 lines (32 loc) · 1.04 KB
/
Copy pathstringProblem1.java
File metadata and controls
38 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package stringProblem;
public class stringProblem1 {
public String replaceChar(String mystring,Character myChar){
String finalString = "";
if ((mystring != null) && (myChar != null)){
for (int i =0; i<mystring.length();i++){
if (mystring.charAt(i) == (myChar)){
continue;
}else{
finalString = finalString + mystring.charAt(i);
}
}
}else{
finalString = "String to be tested or character cannot be null";
}
return finalString;
}
public String deleteChar(String myStr,Character myChar){
Character myemptycharacter = '\0';
if (myStr != null && myChar != null){
myStr = myStr.replace(myChar,myemptycharacter);
}else{
return "String or character to be removed cannot be null";
}
return myStr;
}
public static void main(String[] args){
stringProblem1 myStringProblem1Obj = new stringProblem1();
System.out.println(myStringProblem1Obj.replaceChar("ABCDEFGHIJKLMNOPQRSTUVWXYX",'X'));
System.out.println(myStringProblem1Obj.deleteChar("abcdefghijklmnopqrstuvxxyzx",'x'));
}
}