-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveX.java
More file actions
49 lines (46 loc) · 1.12 KB
/
RemoveX.java
File metadata and controls
49 lines (46 loc) · 1.12 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
39
40
41
42
43
44
45
46
47
48
49
// Remove X
// Send Feedback
// Given a string, compute recursively a new string where all 'x' chars have been removed.
// Input format :
// String S
// Output format :
// Modified String
// Constraints :
// 1 <= |S| <= 10^3
// where |S| represents the length of string S.
// Sample Input 1 :
// xaxb
// Sample Output 1:
// ab
// Sample Input 2 :
// abc
// Sample Output 2:
// abc
// Sample Input 3 :
// xx
// Sample Output 3:
import java.util.Scanner;
public class RemoveX {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter String : ");
String input = s.nextLine();
String ans = removeX(input);
System.out.print("Output : " + ans);
s.close();
}
public static String removeX(String input) {
if (input.length() == 0) {
return "";
}
String ans = "";
if (input.charAt(0) != 'x') {
ans += input.charAt(0);
}
String str = "";
for (int i = 1; i < input.length(); i++) {
str += input.charAt(i);
}
return ans + removeX(str);
}
}