Skip to content

Commit 054195b

Browse files
committed
[Manan] ADD:Removing duplicate characters from string
1 parent 5f03425 commit 054195b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

RemoveDuplicates.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.Scanner;
2+
3+
class RemoveDuplicates {
4+
public static void main(String[] args) {
5+
Scanner input = new Scanner(System.in);
6+
7+
System.out.print("Enter a string: ");
8+
String str = input.nextLine();
9+
10+
// Method to remove duplicates from a string
11+
String result = removeDuplicates(str);
12+
13+
System.out.println("String after removing duplicates: " + result);
14+
}
15+
16+
// Method to remove duplicates from a string
17+
public static String removeDuplicates(String str) {
18+
String result = "";
19+
for (int i = 0; i < str.length(); i++) {
20+
if (result.indexOf(str.charAt(i)) == -1) {
21+
result += str.charAt(i);
22+
}
23+
}
24+
return result;
25+
}
26+
}

0 commit comments

Comments
 (0)