学C#练习1
dnspy吧
全部回复
仅看楼主
level 11
xy9144 楼主
变量和表达式
1,在Main方法中定义变量,用这些变量存储游戏中一个敌人应该有的一些属性,定义尽可能多的变量。
int hp;
float x;
float y;
float z;
float speed;
2,下面哪些变量名不合法?
myVariableIsGood
99Flake
_floor
time2GetJiggyWidIt
wrox.com
3,接受用户输入的两个整数,存储到两个变量里面,交换变量存储的值。
int i = 34;
int j = 3434;
int temp = j;
j = i;
i = temp;
int i = 34;
int j = 3434;
i = j-i;// i3400 j3434
j = j-i;//j 34 i3400
i = j+i;//j = 34 i = 3434
4,编写一个控制台应用程序,要求用户输入4个int值,并显示他们的乘积。
static void Main(string[] args)
{
int a,x, y, z;
a= Convert.ToInt32(Console.ReadLine());
x= Convert.ToInt32(Console.ReadLine());
y= Convert.ToInt32(Console.ReadLine());
z= Convert.ToInt32(Console.ReadLine());
int p=a*x*y*z;
Console.WriteLine("乘积是:{0}", p);
Console.Read();
}
5,从键盘输入一个三位的正整数,按数字的相反顺序输出。
string numStr = "234";
int num =234;
int ge = num%10;
int shi =((num - ge)/10)%10;
int bai =num /100;
static void Main(string[] args)
{
string str= Console.ReadLine();
char[] d = str.ToCharArray();
Console.WriteLine("逆序是:{0}{1}{2}", d[2], d[1], d[0]);
Console.Read();
}
6,编写一个程序,输入梯形的上底 下底 和高 ,计算出来梯形的面积并显示出来。
7,计算半径为n的圆的周长和面积
3.14*n*2
n*n*3.14
string str= Console.ReadLine();
char[] d = str.ToCharArray();
if(str.Length==5)
{
Console.WriteLine("是5位数");
Console.WriteLine("顺序是:{0}{1}{2}{3}{4}", d[0], d[1], d[2], d[3], d[4]);
Console.WriteLine("逆序是:{0}{1}{2}{3}{4}", d[4], d[3], d[2], d[1], d[0]);
}
if (str.Length == 4)
{
Console.WriteLine("是4位数");
Console.WriteLine("顺序是:{0}{1}{2}{3}", d[0], d[1], d[2], d[3]);
Console.WriteLine("逆序是:{0}{1}{2}{3}", d[3], d[2], d[1], d[0]);
}
if (str.Length == 3)
{
Console.WriteLine("是3位数");
Console.WriteLine("顺序是:{0}{1}{2}", d[0], d[1], d[2]);
Console.WriteLine("逆序是:{0}{1}{2}", d[2], d[1], d[0]);
}
if (str.Length == 2)
{
Console.WriteLine("是2位数");
Console.WriteLine("顺序是:{0}{1}", d[0], d[1]);
Console.WriteLine("逆序是:{0}{1}", d[1], d[0]);
}
if (str.Length == 1)
{
Console.WriteLine("是1位数");
Console.WriteLine("顺序是:{0}", d[0]);
Console.WriteLine("逆序是:{0}", d[0]);
}
Console.Read();
}
2015年12月14日 05点12分 1
1