Printing distinct integers in an array

后端 未结 8 1953
遇见更好的自我
遇见更好的自我 2020-12-22 06:17

I\'m trying to write a small program that prints out distinct numbers in an array. For example if a user enters 1,1,3,5,7,4,3 the program will only print out 1,3,5,7,4.

8条回答
  •  有刺的猬
    2020-12-22 06:51

    Try throwing all of the integers into a Set. Duplicates will not ever be added to the Set and you will be left will a set of unique integers.

提交回复
热议问题