Aatul Palandurkar

Find duplicate characters in string

Posted on: August 30, 2021

Objectives:

  • Write a Java program to find duplicate characters in the string and print the duplicate characters
  • Write a program to find duplicate characters in String

Java Program:

public class DuplicateCharacters {
    public static void main(String args[]) {

        String str = "NITIN";
        int count = 0;

        char input[] = str.toCharArray();
        System.out.println("Duplicate Characters are:");

        for (int i = 0; i < str.length(); i++) {
            for (int j = i + 1; j < str.length(); j++) {
                if (input[i] == input [j]) {
                    System.out.println(input[j]);
                    count++;
                    break;
                }
           }
        }
    }
}

Output:

Duplicate Characters are: N I

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 13,219 other followers

Tweets

YouTube

Archives

%d bloggers like this: