0
点赞
收藏
分享

微信扫一扫

5-13.2)以下构造矩形,若length<0 width<0,则抛出无效参数异常

想溜了的蜗牛 2022-04-17 阅读 22
Java

以下构造矩形,若length<0 width<0,则抛出无效参数异常

import java.util.Scanner;

/**
 * @Author cc
 * @create 2022/4/17 19:42
 */
public class Rectangle {
    public Point point1;
    int length;
    int width;
    public Rectangle(Point point1, int length, int width) throws IllegalArgumentException{
        if (length < 0 || width < 0) {
            throw new IllegalArgumentException("矩形:无效参数异常");
        }
        this.point1 = point1;
        this.length = length;
        this.width = width;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Rectangle rectangle = new Rectangle(new Point(scanner.nextInt(),scanner.nextInt()),scanner.nextInt(),scanner.nextInt());
        System.out.println("参数正常");
    }
}

 

举报

相关推荐

0 条评论