Computer Science, asked by georgethomaskambol, 8 months ago

Write a program to input a sentence. Convert the sentence into upper case letters. Display the words along with frequency of the words which have at least a pair of consecutive letters. Sample Input: MODEM IS AN ELECTRONIC DEVICE Sample Output: MODEM DEVICE Number of words containing consecutive letters: 2 in java

Answers

Answered by Anonymous
2

Explanation:

Program to input a sentence. Convert the sentence into upper case letters. Display the words along with frequency of the words which have at least a pair of consecutive letters. Sample Input: MODEM IS AN ELECTRONIC DEVICE Sample Output: MODEM DEVICE Number of words containing consecutive.

Answered by tulika1411200472
10

Answer:

import java.util.*;

class consecutiveLetters

{

   

  public static void main()

 {    

     System.out.println("Input a sentence");

     Scanner S=new Scanner(System.in);

     String Str=S.nextLine();

     int len=Str.length();

     int a=0;

     int b=0;

     String sub ="";

     int frequency=0;

     Str=Str.toUpperCase();

     Str=Str+" ";

     System.out.println(Str+"1");

     for(int i=0;i<len;i++)

     {  

         if(Str.charAt(i)==' ')

         {  

             b=i;

             sub=Str.substring(a,b);

             a=b;

             

             for(int j=0;j<sub.length()-1;j++)

             {

                 int x=sub.charAt(j);

                 int y=sub.charAt(j+1);

                 if(x==(y-1))

                 {  

                     System.out.println(sub);

                     frequency++;

                   }

               }

           }

       }

       

             

        System.out.println("Number of words containing consecutive letters: "+frequency);

       }

   }    

Explanation:

Similar questions