Java examples for Algorithm:String
Does string have duplicate characters next to each other
public class Main { public static void same(String s) { int count = 0; char c[] = s.toCharArray(); for (int i = 0; i != c.length - 1; i++) { if (c[i] == c[i + 1]) count++;/*from ww w. j a v a 2 s .c o m*/ } System.out.println(count); } public static void main(String[] args) { same("aaccc"); } }