Sign up ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I solved a problem recently and I want to check the code I have written is good or is a bad design. Is good or poor in terms of efficiency. The problem is given an input string count the number of occurrence of each character in the string and print it, example:

Input String is: fffdddssaaa
Result is f3d3s2a3

My Program:

public class StringCount {
    static String process(String s) {

        System.out.println("Input String is: " + s);
        char[] array = s.toCharArray();



        int j = 0;
        int m = 0;
        int i = 0;

        int t = 0;
        int count = 0;
        StringBuilder str = new StringBuilder();
        for (j = 0; j < s.length(); j++) {

            m = 0;
            for (i = 0; i < s.length(); i++) {

                if (array[j] == array[i]) {
                    m++;
                }

            }
            //System.out.println("char " + array[j] + " is " + m);
            String ss = str.toString();
            char[] temp = ss.toCharArray();

            if (count == 0) {
                str.append(array[j]);
                str.append(m);
                ss = str.toString();
                temp = ss.toCharArray();
                count++;
            } else if (count > 0) {

                if (temp[t] == array[j]) {

                } else {
                    str.append(array[j]);
                    str.append(m);
                    ss = str.toString();
                    temp = ss.toCharArray();
                    t = t + 2;
                }

            }

        }
        System.out.println("Result is " + str);



        return str.toString();

    }

    public static void main(String[] args) {
        process("fffdddssaaa");
    }
}

Please provide your valuable reviews of this code. Thanks

share|improve this question

put on hold as off-topic by JS1, rolfl, Manny Meng, SuperBiasedMan, Hosch250 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – JS1, rolfl, Manny Meng, SuperBiasedMan, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Everyone who posts here wants "some comments on their programming skills" please change the title to reflect what the code does. –  ratchet freak Oct 6 at 18:27
4  
Also, please indicate whether the input 'ffaattffaarrtt' should give the output 'f2a2t2f2a2r2t2' or 'f4a4t4r2' –  rolfl Oct 6 at 18:41
    
Have you already learned about HashMap? –  PM 77-1 Oct 6 at 18:55
    
'ffaattffaarrtt' should actually give an output as f4a4t4r2 –  alicin wonderland Oct 6 at 19:39
    
How can I use Hashmap here ? –  alicin wonderland Oct 6 at 19:39

Browse other questions tagged or ask your own question.