write a program to print duplicate string
Answers
Answer:
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: ");
Explanation:
I hope it helps you
please mark me as brainleast
Define a string.
Two loops will be used to find the duplicate characters. Outer loop will be used to select a character and initialize variable count by 1.
Inner loop will compare the selected character with rest of the characters present in the string.
If a match found, it increases the count by 1 and set the duplicates of selected character by '0' to mark them as visited.
After inner loop, if count of character is greater than 1, then it has duplicates in the string.