Write a program to accept a string. Convert the string to uppercase. Count and output the number of Consecutive letter pairs that exist in the string.
Sample Input: “IT WAS NOT TOUGH FOR HIM TO RESIDE ABOVE THE HILL”
Sample Output:
Number of consecutive pair of characters = 6
Answers
Answered by
3
Answer:
import java.util.Scanner;
public class LetterSeq
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String s = in.nextLine();
String str = s.toUpperCase();
int count = 0;
int len = str.length();
for (int i = 0; i < len - 1; i++) {
if (str.charAt(i) == str.charAt(i + 1))
count++;
}
System.out.println("Double Letter Sequence Count = " + count);
}
}
Explanation:
Similar questions
Social Sciences,
5 months ago
Computer Science,
5 months ago
Physics,
5 months ago
Hindi,
10 months ago
Math,
10 months ago
Sociology,
1 year ago
Sociology,
1 year ago