Count the unique characters in a given String
String: Sateesh
Output: 3
public class Demo200 {
public static void main(String[] args) {
String s="sateesh";
StringBuffer str=new StringBuffer(s);
for (int i = 0; i < str.length(); i++)
{
int flag = 0;
for (int j = 0; j < str.length(); j++)
{
if (str.charAt(i) == str.charAt(j) && i != j)
{
flag = 1;
break;
}
}
if (flag == 0)
System.out.print(str.charAt(i));
}
}
}
Output:
3
more programs visit http://sateeshm.com/
No comments:
Post a Comment