Skip to main content

Java program to find out Repeated characters in a String

Java program to find out Repeated characters in a String.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package logic;
 
import java.util.ArrayList;
import java.util.Scanner;
 
public class Stringrepeat 
{
 
public static void main(String[] args) 
{
 
	 System.out.println("enter the string ");
	 Scanner s = new Scanner(System.in);
 
	 String b=s.next();
 
	  for(int i=0;i<b.length()-1;i++)
	   {
		  for(int j=i;j<b.length()-1;j++)
		  { 
 
	            if(b.charAt(i)==b.charAt(j+1))
	            {
		     System.out.println("repeating chararcter is "+b.charAt(i));
	           }
	         }
	   }
	}
    }

output:

1
2
3
4
5
enter the string 
aabbgjg
repeating chararcter is a
repeating chararcter is b
repeating chararcter is g