格式化错误
时间:2011-12-18
来源:互联网
using System;
using System.Windows.Forms;
public class Test
{
static void Main()
{
Rectangle rec1 = new Rectangle(10, 20, 100, 50);
string output = "rec1:";
output += rec1.Print();
rec1.Inflate(20, 20);
output += "rec1Inflate:";
output += rec1.Print();
MessageBox.Show(output, "输出结果");
}
}
//
public class Rectangle
{
private int x;
private int y;
private int width = 10;
private int height = 20;
public Rectangle(int myx, int myy, int mywidth, int myheight)
{
x = myx;
y = myy;
width = mywidth;
height = myheight;
}
public int X
{
set { x = value; }
get { return x; }
}
public int Y
{
set { y = value; }
get { return y; }
}
public int Height
{
set
{
if (value > 0)
height = value;
}
get { return height; }
}
public int Width
{
set
{
if (value > 0)
width = value;
}
get { return width; }
}
public int Area
{
get { return width * height; }
}
public void Inflate(int inwidth, int inheight)
{
X = X - inwidth;
Y = Y - inheight;
Height = Height + 2 * inheight;
Width = width + 2 * inwidth;
}
public string Print()
{
string str = string.Format("X={0},Y={1}.",X,Y)+"\n";
str += string.Format("Width={0],Height={1}.", Width, Height) + "\n";
str += string.Format("Area={0}", Area) + "\n";
return str;
}
}
using System.Windows.Forms;
public class Test
{
static void Main()
{
Rectangle rec1 = new Rectangle(10, 20, 100, 50);
string output = "rec1:";
output += rec1.Print();
rec1.Inflate(20, 20);
output += "rec1Inflate:";
output += rec1.Print();
MessageBox.Show(output, "输出结果");
}
}
//
public class Rectangle
{
private int x;
private int y;
private int width = 10;
private int height = 20;
public Rectangle(int myx, int myy, int mywidth, int myheight)
{
x = myx;
y = myy;
width = mywidth;
height = myheight;
}
public int X
{
set { x = value; }
get { return x; }
}
public int Y
{
set { y = value; }
get { return y; }
}
public int Height
{
set
{
if (value > 0)
height = value;
}
get { return height; }
}
public int Width
{
set
{
if (value > 0)
width = value;
}
get { return width; }
}
public int Area
{
get { return width * height; }
}
public void Inflate(int inwidth, int inheight)
{
X = X - inwidth;
Y = Y - inheight;
Height = Height + 2 * inheight;
Width = width + 2 * inwidth;
}
public string Print()
{
string str = string.Format("X={0},Y={1}.",X,Y)+"\n";
str += string.Format("Width={0],Height={1}.", Width, Height) + "\n";
str += string.Format("Area={0}", Area) + "\n";
return str;
}
}
作者: a609091648 发布时间: 2011-12-18
没看出有啥错误啊,能否把你错误标出来?
作者: gxingmin 发布时间: 2011-12-18
你拷贝到程序里一运行就知了、
作者: a609091648 发布时间: 2011-12-18
引用 1 楼 gxingmin 的回复:
没看出有啥错误啊,能否把你错误标出来?
没看出有啥错误啊,能否把你错误标出来?
你拷进去运行就知道了、
作者: a609091648 发布时间: 2011-12-18
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28