Count different values in array in Java

后端 未结 9 1621
借酒劲吻你
借酒劲吻你 2021-02-10 17:15

I\'m writing a code where I have an int[a] and the method should return the number of unique values. Example: {1} = 0 different values, {3,3,3} = 0 different values, {1,2} = 2 d

9条回答
  •  灰色年华
    2021-02-10 17:48

    Try this... its pretty simple using ArrayList. You don't even need two loop. Go on

    import java.util.*;
    public class distinctNumbers{
    
     public static void main(String []args){
        int [] numbers = {2, 7, 3, 2, 3, 7, 7};
        ArrayList list=new ArrayList();
        for(int i=0;i

提交回复
热议问题