
1条回答 默认 最新
BigDong~ 2021-11-11 10:56关注public class Triangle {
private static AtomicInteger count = new AtomicInteger(0); private int a; private int b; private int c; Triangle(int a, int b, int c) { if (count.intValue() >= 10) { throw new RuntimeException("创建对象数量超过10个"); } if (a + b < c || a + c < b || b + c < a) { throw new RuntimeException("参数不符合三角形约束条件"); } this.a = a; this.b = b; this.c = c; count.incrementAndGet(); }}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报