You are viewing a single comment's thread. Return to all comments →
Here is the solution. Please comment if you have beter approach
public static void main(String[] args) { Scanner in = new Scanner(System.in); int nooftestcases = in.nextInt();
for (int i = 1; i <= nooftestcases; i++) { String test = in.next(); int count=0; for (int j = 0; j < test.length()-1; j++) { if(test.charAt(j)==test.charAt(j+1)) count++; } System.out.println(count); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
Here is the solution. Please comment if you have beter approach
public static void main(String[] args) { Scanner in = new Scanner(System.in); int nooftestcases = in.nextInt();