File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ class RemoveCharacter {
4
+ // Main method
5
+ public static void main (String [] args ) {
6
+ Scanner input = new Scanner (System .in );
7
+
8
+ System .out .print ("Enter a string: " );
9
+ String str = input .nextLine ();
10
+
11
+ System .out .print ("Enter a character to remove: " );
12
+ char ch = input .next ().charAt (0 );
13
+
14
+ // Method to remove a specific character from the string
15
+ String result = removeCharacter (str , ch );
16
+
17
+ System .out .println ("String after removing character: " + result );
18
+
19
+ input .close ();
20
+ }
21
+
22
+ // Method to remove a specific character from the string
23
+ public static String removeCharacter (String str , char ch ) {
24
+ String result = "" ;
25
+ for (int i = 0 ; i < str .length (); i ++) {
26
+ if (str .charAt (i ) != ch ) {
27
+ result += str .charAt (i );
28
+ }
29
+ }
30
+ return result ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments