C#思考题!???
using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
int a=32,b;
double c=2.7,d;
char e= 'D ',f;
b=a+c; //A
d=a+c;
f=a+e;
Console.Write( "b= ");
Console.WriteLine(b);
Console.Write( "d= ");
Console.WriteLine(d);
Console.Write( "f= ");
Console.WriteLine(f);//B
Console.WriteLine(b+d+f); //C
}
}
}
/*上机要求
修改程序能正常运行
修改程序A行,对b的输出值四舍五入。
修改程序B行,按整型值输出f。
分析C行数据的值的类型。*/
------解决方案--------------------using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
int a=32,b;
double c=2.7,d;
char e= 'D ',f;
if(((a+c)*10%10)> 5)
b=Convert.Int32(Math.Ceiling(a+c)) ;
else
b=Convert.Int32(Math.Floor(a+c)) ; //A
d=a+c;
f=Convert.ToChar(a+Convert.ToInt32(e);
Console.Write( "b= ");
Console.WriteLine(b);
Console.Write( "d= ");
Console.WriteLine(d);
Console.Write( "f= ");
Console.WriteLine(Conver.Int32(f));//B
Console.WriteLine((b+d+f).Gettype().ToString()); //C
}
}
}