lemsca 2023-04-04 11:52 采纳率: 71.4%
浏览 24
已结题

关于#输出#的问题,如何解决?


import java.util.Scanner;

class Rectangle {
    private double length, width;
    public Rectangle (double length,double width){
    super();
    this.length=length;
    this.width=width;
    }
    public Rectangle(double side){
    super();
    this.length=side;
    this.width=side;
    }
    public Rectangle(){
    }
    public double getLength(){
    return length;}
    public void setLength(double length){
    if(length<0)
    {
    System.exit(-2);
    }
    this.length=length;
    }
    public double getWidth(){
    return width;
    }
    public void setWidth(double width){
    if(width<0){
    System.exit(-2);
    }
    this.width=width;
    }
    public double getPerimeter(){
    return 2*(width+length);
    }
    public double getArea(){
    return width*length;
    }

}

public class TestRectangle {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter the length and width of rectangle r1:");
        double length = sc.nextDouble();
        double width = sc.nextDouble();
        System.out.println("Please enter the side length of square r2:");
        double side = sc.nextDouble();

        Rectangle r1 = new Rectangle(length, width);
        Rectangle r2 = new Rectangle(side);
        Rectangle r3 = new Rectangle();

        System.out.printf("The perimeter of r1 is %.2f\n", r1.getPerimeter() );
        System.out.printf("The area of r2 is %.2f\n", r2.getArea() );
        System.out.printf("The perimeter of r3 is %.2f\n", r3.getPerimeter() );

        r3.setLength(r1.getLength());
        r3.setWidth(r2.getWidth());
        System.out.printf("After modification, the area of r3 is %.2f\n", r3.getArea() );

        System.out.println("Please enter the length and width of rectangle r3:");
        double r3_length = sc.nextDouble();
        double r3_width = sc.nextDouble();
        sc.close();
        r3.setLength(r3_length);
        r3.setWidth(r3_width);
        System.out.printf("After modification, the area of r3 is %.2f\n", r3.getArea() );
    }
}


为什么最后一行没有输出呢

  • 写回答

3条回答 默认 最新

  • 关注

    img


    有输出

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月10日
  • 已采纳回答 4月10日
  • 创建了问题 4月4日

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上