Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need a java code for finding repeating characters in a string .Please help
Posted
Comments
Ravi Bhavnani 5-Jan-15 23:51pm    
What have you tried?

/ravi

Sorry we do not do your homework, it is set to demonstrate how much you have learned. This is a fairly trivial question if you just spend some time working through some of the tutorials, such as http://docs.oracle.com/javase/tutorial/java/data/index.html[^].
 
Share this answer
 
C#
public class FirstRepeatedString {
    public static void main(String[] args) {
        System.out.println("Enter the String !");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        getRepeated(str);

    }
public static void getRepeated(String name) {
	    Map<character,> map = new HashMap<character,>();
	    for(int i = 0; i < name.length(); i++) {
	        char c = name.charAt(i);
	        Integer count = map.get(c);
//	        System.out.println("count value " + count);
	        if (count == null) {
	            count = 0;
	        }
	        map.put(c, count + 1);
	    }
	    Set<character> a = map.keySet();
//	    System.out.println("Set value " + a);
	    for (Character t : a) {
	        System.out.println(t + " Ocurred " + map.get(t) + " times");
	    }
	}
}</character>
 
Share this answer
 
Comments
Richard MacCutchan 7-Jan-15 11:53am    
You do not help people by writing their assignments for them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900