using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
double zhongliang = Convert.ToDouble(Console.ReadLine());
double tiji = Convert.ToDouble(Console.ReadLine());
PhysicalObject p = new PhysicalObject(zhongliang,tiji);
p.MyMethod();
Console.ReadKey();
}
}
class PhysicalObject
{
private double weight;
private double tiji;
double midu;
public PhysicalObject(double w,double ti)
{
weight = w;
tiji = ti;
}
public double get_weight()
{
return weight;
}
public double get_tiji()
{
return tiji;
}
public void MyMethod()
{
midu = weight / tiji;
if (midu>1)
{
Console.WriteLine("物体会下沉");
}
else
{
if (midu==1)
{
Console.WriteLine("物体会悬浮在水面");
}
else
{
Console.WriteLine("物体会静止后漂浮");
}
}
}
}
}
c#————关于物体是否在水中下沉
最新推荐文章于 2022-03-10 14:11:17 发布
本文介绍了一个简单的C#程序,该程序通过输入物体的重量和体积来计算物体的密度,并据此判断物体放入水中后的状态:下沉、悬浮还是漂浮。
1331

被折叠的 条评论
为什么被折叠?



