Question
Find the duplicate characters of a sentence
Enter the sentence:
the quick brown fox jumped over the lazy dog
D
E
H
O
R
T
U
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
Java
Python
Java
import java.util.Scanner;
public class program
{
public static void main(String[] args)
{
String sen="";
char ch=' ',ch1=' ';
int i=0,count=0,len=0,asciiValueOfA=0,asciiValueOfZ=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence:");
sen = sc.nextLine();
sen=sen.toUpperCase();
asciiValueOfA=(int)'A';
asciiValueOfZ=(int)'Z';
len=sen.length();
System.out.println("Duplicate characters in given sentence:);
for(ch='A';ch<='Z';ch++)
{
count=0;
for(i=0;i< len;i++)
{
ch1=sen.charAt(i);
if(ch==ch1)
{
count++;
}
}
if(count>1)
{
System.out.println(ch);
}
}
}
}
Python
sen=input("Enter a sentence:")
sen=sen.upper()
count=0
length=len(sen)
# ord('A') will return ASCII value of character 'A'
asciiValueOfA=ord('A')
# ord('Z') will return ASCII value of character 'Z'
asciiValueOfZ=ord('Z')
print("Duplicate Characters in given Sentence:")
for i in range(asciiValueOfA,asciiValueOfZ+1):
count = 0
for ch in sen:
#chr(i) will return character whose ASCII value is i
# for example if i value is 65 then
# chr(65) will return character 'A'
if(chr(i)==ch):
count=count+1
if(count>1):
print(chr(i))
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale