using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 類方法3
{
class Program
{
public static void Main(string[] args)
{
int length=0;
int width=0;
Console.WriteLine("請輸入長和寬");
length = Console.Read();
width = Console.Read();
rectangle r = new rectangle(length,width);
r.mianji();
r.zhouchang();
Console.ReadKey();
}
}
public class rectangle
{
int c = 0;
int s=0;
public int Length
{
get;
set;
}
public int Width
{
get;
set;
}
public rectangle(int length,int width)
{
this.Length=length;
this.Width =width;
}
public void mianji()
{
c = (Length + Width) * 2;
Console.WriteLine("周長是"+c);
}
public void zhouchang()
{
s = (Length) *(Width);
Console.WriteLine("面積是"+s);
}
}
}
為什么鍵盤打的數與程式輸入的數不一致?
uj5u.com熱心網友回復:
static void Main(string[] args)
{
int length = 0;
int width = 0;
Console.WriteLine("請輸入長和寬");
length = int.Parse(Console.ReadLine());
width = int.Parse(Console.ReadLine());
rectangle r = new rectangle(length, width);
r.mianji();
r.zhouchang();
Console.ReadKey();
}
uj5u.com熱心網友回復:
要注意int和string之間的轉換uj5u.com熱心網友回復:
為什么運行的時候顯示輸入字串的格式不對
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/285243.html
標籤:C#
上一篇:怎么讓for回圈走完
