Write a program to input a string and convert into uppercase and count double letters present in it.
Eg : rabbit eats carrots
Output : 2
Answers
Answered by
9
import java. io.*;
class double
{
public static void main(String args[])throws Exception
{
DataInputStream in=new DataInputStream(System . in);
{
int i, j,ctr= 0;
String s;
char ch, c;
System . out. println("Enter any string");
s= in . readLine();
s=to. UpperCase();
for(i=0;i<s . length();i++)
{
ch=s . charAt(i);
for(j=(i+1);j<s . length();j++)
{
c=s . charAt(j);
if(ch==c)
ctr++;
}
}
System . out. println("Number of doubled words are"+ctr);
}
}
s=I like apple.
ctr will be =1
So,
Answered by
0
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:
input = rabbit eats carrots
output = 2
Similar questions