We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f03425 commit 054195bCopy full SHA for 054195b
RemoveDuplicates.java
@@ -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
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