Posted by: ganatantranepal April 28, 2008
Java Program Help Plz
Login in to Rate this Post:     0       ?        
Hey mate,
Problem solved !!!!!!

/* FOR SAJHA MATE */

package sajhabro;

public class Sort {
    public static void main(String[] args) {
        int[] a = new int[] { 1, 4, 5, 4, 4, 1 };
        int temp = 0, count = 1;
//SORTS UNSORTED ARRAY
        for (int i = 0; i < a.length; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] > a[j]) {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        System.out.println("Number\t\tCount");
//PRINTS SORTED ARRAY AND COUNTER
        for (int i = 0; i < a.length; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] == a[j] && a[j] != '*') {
                    a[j] = '*';
                    count++;
                }
            }
            if (a[i] != '*')
                System.out.println(a[i] + "\t\t" + count);
            count = 1;
        }
    }
}

Last edited: 28-Apr-08 09:47 PM
Last edited: 28-Apr-08 09:49 PM
Read Full Discussion Thread for this article