Skip to main content

Posts

Showing posts with the label duplicate characters

Print all duplicate characters from a string

 In this question, we have to print duplicate characters i.e. the characters which come more than once in the given string. ex:- java (in "java",  'a' is the only duplicate character as it comes more than once, other than that 'j' and 'v' comes only one time in the given string ). python ( in "python" all the characters come only on time so there is no duplicate character in the given string "python"). Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.Scanner; public class PrintDuplicateCharacters { public static void main (String[] args) { Scanner sc = new Scanner(System. in ); String duplicate_str = "" ; String str = sc. next (); for ( int i = 0 ; i < str. length (); i++) { char c = str. charAt (i...