calculate the character in string
public class HelloWorld{
public static void main(String []args){
String string1 = "Hello World";
int count;
char string[] = string1.toCharArray();
for(int i = 0; i <string.length; i++) {
count = 1;
for(int j = i+1; j <string.length; j++) {
if(string[i] == string[j] && string[i] != ' ') {
count++;
string[j] = '0';
}
}
if(count > 1 && string[i] !='0') {
System.out.println(string[i]+":-"+count);
}else if (string[i]!='0'&& string[i]!=' '){
System.out.println(string[i]+":-"+count);
}
}
}
}
Comments
Post a Comment