java吧 关注:1,252,026贴子:12,737,540
  • 10回复贴,共1

新人初学,老司机带带路

只看楼主收藏回复

设计一个类,描述矩形,有两个属性
– width
– height
包含一个drawRect()方法,在屏幕上使用“#”画出空心矩形
例子:
# # # # # # # #
# #
# # # # # # # #
怎么做,百度了一下 第一个回答运行不了


IP属地:四川1楼2015-07-18 20:26回复
    class Rectangle
    {
    int width;
    int height;
    Public:
    Rectangle(int =0,int =0);
    Rectangle(const Rectangle &);
    void drawRect();
    ~Rectangle(){}
    };
    Rectangle::Rectangle(int w=0,int h=0)
    {
    width=w;
    height=h;
    }这是百度的
    Rectangle::Rectangle(const Rectangle & x)
    {
    width=x.width;
    height=x.height;
    }
    void Rectangle::drawRect()
    {
    for(int i=0;i<height;i++)
    {for(int j=0;j<width;j++)
    if(0==i||0==j||i==width-1||j==height-1)
    cout<<"#";
    else
    cout<<" ";
    cout<<endl;
    }
    }


    IP属地:四川2楼2015-07-18 20:27
    回复
      那是C++的代码


      3楼2015-07-18 20:39
      收起回复
        # # # # # # # #
        # #
        # # # # # # # #
        只输出个着吗?那两属性有什么用啊,太简单了吧


        IP属地:河南4楼2015-07-18 21:15
        收起回复
          syso(########);
          syso(##);
          syso(########);


          5楼2015-07-18 21:21
          收起回复