Untitled

Anonymous
Plain Text
08/23/2025 5:12 AM
607 B
12
Indexable
Never
import java.util.Arrays;

public class IArray {
    public static void main(String[] args) {
        int[] rollno = new int[]{10, 50, 30, 40, 15};
        Arrays.sort(rollno);
        for (int i = 0; i < rollno.length; i++) {
            int cnt = 1;
            while (i + 1 < rollno.length && rollno[i] == rollno[i + 1]) {
                cnt++;
                i++;
            }
            System.out.println(rollno[i] + " " + cnt);
        }
        
        System.out.println("The roll no is ");
        for (int i : rollno) {
            System.out.println(i);
        }
    }
}
Editor is loading...
Leave a Comment