Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(strings) A character double occurs when the same character occurs twice in a ro

ID: 3755445 • Letter: #

Question

(strings) A character double occurs when the same character occurs twice in a row, such as the "mm" in "programming". Note the character could be a symbol, such as"" or"!!". For example, the words below all contain character doubles: Hello, good, xt+, follow Write a full Java program that counts the number of character double:s in a phrase entered by the user. The output should look like the example below Enter phrase: Follow Programming Concepts!! Output: There are 3-character doubles. . letters, nor do you have to handle the case when a character occurs three times or more in a row

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg_double_characters;
import java.util.*;
/**
*
* @author Debasis
*/
public class Chegg_Double_Characters {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
String text = new String();
int count = 0;
System.out.print(" Enter the phrase : ");
text = sc.nextLine();
char[] char_ar = text.toCharArray();
for(int i=0;i<char_ar.length-1;i++)
{
if(char_ar[i] == char_ar[i+1])
{
//System.out.println(char_ar[i]+" "+char_ar[i+1]);
count++;
}
}
System.out.println("There are "+count+"-character doubles.");
  
}
  
}

Note - For any more query, pls reply in the comment section.