Question:
Program to remove duplicate characters in the given string
Input: 123346778
Output: 12345678
Program:
import java.io.*;
public class LetUsCodeinJava {
public static void main(String[ ] args){
String inpStr = "123346778";
String resStr = "";
for(int i = 0; i < inpStr.length( ); i++){
if(!resStr.contains(String.valueOf(inpStr.charAt(i)))){
resStr += String.valueOf(inpStr.charAt(i));
}
}
System.out.println(resStr);
}
}
Output:
12345678
0 comments:
Post a Comment