Computer Science, asked by shawrenpathre1, 10 months ago

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 soumyadeepdutta2006
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