矩形.txt

来自「最常用的50个经典程序」· 文本 代码 · 共 57 行

TXT
57
字号
using System;
class Rectangle
{
	private float length=1.0f;
	private float width=1.0f;

	public float SetLength(float length)
	{
		this.length=length;
		if((length<0.0f)||(length>2.0f))
		{
			Console.WriteLine ("长的取值范围应在1.0-2.0之内,请重新设值。");
			return 0.0f;
		}
		return width;
	}
	public float SetWidth(float width)
	{
        this.width=width;
		if((width<0.0f)||(width>2.0f))
		{
			Console.WriteLine ("宽的取值范围应在1.0-2.0之内,请重新设值。");	
			return 0.0f;
		}
		return width;
	}
	public float GetLength(float length)
	{
		return length;
	}
	public float GetWidth(float width)
	{
		return width;  
	}
	public float perimeter()
	{
		return length*2+width*2;
	}
	public float area()
	{
	   return length*width;
	}

}
class Rectangle_Test
{
	public static void Main()
	{
		Rectangle r1=new Rectangle ();
		r1.SetLength (1.8f);
		r1.SetWidth (1.2f);
	    Console.WriteLine (r1.perimeter ());
		Console.WriteLine (r1.area ());

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?