Computer Science, asked by kashyaphk, 10 months ago

How do you print duplicate characters from a string?​

Answers

Answered by DrAvinash
1

JAVA

public class DuplicateCharacters {

public static void main(String[] args) {

String string1 = "Great responsibility";

int count;

//Converts given string into character array.

char string[] = string1.toCharArray();

System.out.println("Duplicate characters in a given string: ");

Answered by lovepreetsingh09
2

Answer:

string = "Great responsibility";

print("Duplicate characters in a given string: ");

#Counts each character present in the string

for i in range(0, len(string)):

count = 1;

for j in range(i+1, len(string)):

if(string[i] == string[j] and string[i] != ' '):

count = count + 1;

#Set string[j] to 0 to avoid printing visited character

string = string[:j] + '0' + string[j+1:];

#A character is considered as duplicate if count is greater than 1

if(count > 1 and string[i] != '0'):

print(string[i]);

mark me brainlist and follow me✌✌✌✌

Similar questions