Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how do you print duplicate characters from a string?

import java.util.Scanner;
public class uniqueCharacters {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter a string:");
        String str = scan.nextLine();

        char currentChar;
        int count=0;
        String duplicateCharacter="";
        for (int i = 0; i < str.length(); i++) {
            currentChar=str.charAt(i);

            for (int j = 0; j < str.length(); j++) {
                if (currentChar==str.charAt(j)) {
                    count++;
                }
            }
            
            if(count!=1 && !duplicateCharacter.contains(currentChar+"")){

                duplicateCharacter+=currentChar+" ";
            }
            count=0;
        }

        System.out.println(duplicateCharacter);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: spring boot resource optional request param 
Java :: how to convert object to list in java 
Java :: l,og in android studio 
Java :: icon button java 
Java :: javafx listview get item index 
Java :: cannot lock java compile cache as it has already been locked by this process 
Java :: gradle fatjar 
Java :: java reverse value of boolean 
Java :: java find item in list by property 
Java :: java deltaTime 
Java :: fullscreen in java 
Java :: check if map contains key java 
Java :: java for schleife 
Java :: StringBuilder java pop back 
Java :: find number of days between two local dates in java 8 
Java :: javaee .jsp get value of object with EL 
Java :: change date jdatepicker java 
Java :: java int to octal 
Java :: hql return new object from query 
Java :: jpa validation string only number 
Java :: how to change orientation of linearlayout in recyclerview android 
Java :: java create set with values 
Java :: spigot action bar 
Java :: rates api 
Java :: jlabel on the center of a jpanel 
Java :: create map java 
Java :: spring value # vs $ 
Java :: java 11 initialize map 
Java :: javadoc links to url 
Java :: hide actionbar android 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =