还有一种思路就是把数字分解,然后把每个数字都放入Set中,因为Set中是不会存在相同的元素的,所以比较Set的大小和字符串的大小就可以知道有没有重复数字了,相同则没有,Set的长度小于字符串长度则存在相同数字
public static void main( String[] args ) {
Integer num = 1234444890;
Integer remain = 0;
Integer count = 0;
java.util.Set set = new java.util.HashSet<>();
while(num > 0) {
remain = num % 10;
set.add(remain);
num /= 10;
count++;
}
boolean hasRepeatNum = set.size() != count;
System.out.println("有没有重复数字=" + hasRepeatNum);
}