代码如下:
import java.util.*;
public class Test {
public static void main(String[] args) {
Set customerNumSet = getCustomerNumSet();
customerNumSet.forEach(e->{
System.out.println(e.getA()+" "+e.getB()+" "+e.getC());
});
int retSum=321+211;
System.out.println(retSum);
}
public static Set getCustomerNumSet(){
Random random = new Random();
HashSet customerNumHashSet = new HashSet<>();
int count=0;
while (true){
int intA = random.nextInt(10);
int intB = random.nextInt(10);
int intC = random.nextInt(10);
String numStr1 = String.valueOf(intA) + String.valueOf(intB) + String.valueOf(intC);
int num1 = Integer.parseInt(numStr1);
String numStr2 = String.valueOf(intB) + String.valueOf(intC) + String.valueOf(intC);
int num2 = Integer.parseInt(numStr2);
int sum = num1 + num2;
if (532==sum){
CustomerNum customerNum = new CustomerNum();
customerNum.setA(intA);
customerNum.setB(intB);
customerNum.setC(intC);
customerNumHashSet.add(customerNum);
}
count++;
if (count>1000000){
break;
}
}
return customerNumHashSet;
}
}
class CustomerNum{
private Integer a;
private Integer b;
private Integer c;
public Integer getA() {
return a;
}
public void setA(Integer a) {
this.a = a;
}
public Integer getB() {
return b;
}
public void setB(Integer b) {
this.b = b;
}
public Integer getC() {
return c;
}
public void setC(Integer c) {
this.c = c;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CustomerNum that = (CustomerNum) o;
return Objects.equals(a, that.a) &&
Objects.equals(b, that.b) &&
Objects.equals(c, that.c);
}
@Override
public int hashCode() {
return Objects.hash(a, b, c);
}
@Override
public String toString() {
return "CustomerNum{" +
"a=" + a +
", b=" + b +
", c=" + c +
'}';
}
}



