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 str= sc.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);
}
}

import java .util.Scanner;
ReplyDeleteclass 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