栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

获取特殊数字组合 abc+bcc=532

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

获取特殊数字组合 abc+bcc=532

获取特殊数字组合 abc+bcc=532 Java代码实现

代码如下:

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 +
                '}';
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/993183.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号