I d like to ask whether anybody knows a simple way to calculate the letters of a phrase and the adjacent repeating letters till '#' occurs,,,
For example:
Hello Harry! [Goodmorning]#
Letters : 21
Adjacent repeating letters: 3
Thanx a lot!!!:) :) :)
Printable View
I d like to ask whether anybody knows a simple way to calculate the letters of a phrase and the adjacent repeating letters till '#' occurs,,,
For example:
Hello Harry! [Goodmorning]#
Letters : 21
Adjacent repeating letters: 3
Thanx a lot!!!:) :) :)
Code:public class AdjacentCount {
public static void main(String[] args) {
String text = "Hello Harry! [Goodmorning]#";
int length = text.length();
int count = 0;
int pos = 0;
while(pos < length-1) {
if(text.charAt(pos) == text.charAt(pos+1)) {
System.out.println("found match " + text.charAt(pos) +
" at " + pos + " and " + (pos+1));
count++;
}
pos++;
}
System.out.println("count = " + count);
}
}