Java Program to count and output the number of double letter sequences that exist in the string.


 import java.util.Scanner;


class DoubleFrequencyLetter
{

public static void main(String[] arg)
{
Scanner sc = new Scanner(System.in);

//Ask for user input
System.out.print("Enter String");
String strsc.nextLine();

//initialise the variable 'count' as 0
int count=0;

// convert the string into UPPER CASE and store it in a String 'str1'
String str1=str.toUpperCase();

for(int i=0 ;i<str1.length()-1;i++)
{
  //check whether the two adjacent characters are same and increase the count 
   if(str1.charAt(i)==str1.charAt(i+1))
    {
         count++;    
    }
}

// print the number the double frequency letter
System.out.println("No of Double Frequency letter"+count);
    
}
}

Comments

  1. import java .util.Scanner;
    class repeat
    {
    public static void main()
    {
    Scanner sc=new Scanner (System.in);
    System.out.println("Enter a sentence");
    String s=sc.nextLine();
    int l=s.length();
    String s1=s.toUpperCase();
    System.out.println(s1);
    int c=0;
    for(int i=0;i<l-1;i++)
    {
    if(s.charAt(i)==s.charAt(i+1))
    {
    c++;
    System.out.println((char)i);

    }
    System.out.println("Double letter sequences count"+c);
    }
    }
    }

    WHAT IS WRONG IN THIS CODE

    ReplyDelete

Post a Comment

Popular posts from this blog

Java Program to replace vowel with next immediate character alphabetically in a String.

Java Program to find the minimum and maximum palindrome String in a Sentence