2021-11-16

public class Rectangle {
   
    private Integer length;
    private Integer width;
    public void setDemo(Integer length, Integer width){
   
        if(length < 0){
   
            throw new RuntimeException("length 不能小于0");
        }
        if(width < 0){
   
            throw new RuntimeException("width 不能小于0");
        }
        this.length = length;
        this.width = width;
    }
    public Integer arer(){
   
        return length * width;
    }
}
public class Test {
   
    public static void main(String[] args) {
   
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入length:");
        int length = scanner.nextInt();
        System.out.println("请输入width:");
        int width = scanner.nextInt();
        Rectangle rectangle = new Rectangle();
        rectangle.setDemo(length,width);
        System.out.println(rectangle.arer());
    }
}
 
全部评论

相关推荐

_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务