第1题:有个叫卡卡西的人在旅店登记的时候前台让他填一张表,这张表里的内容要存到电脑上,有姓名、年龄、邮箱、家庭住址、工资,之后把这些信息显示出来。
输出:我叫卡卡西,我住在火影村,我今年30了,我的邮箱是kakaxi@qq.com,我的工资是2000。
法1:
using System;
namespace 变量
{
class Program
{
static void Main(string[] args)
{
String name = "卡卡西";
int age = 30;
string email = "kakaxi@qq.com";
string address = "火影村";
decimal salary = 5000m;
Console.WriteLine("我叫" + name + ",我住在" + address + ",我今年" + "age" + "了" + ",我的邮箱是" + email + ",我的工资是" + salary+"。");
Console.ReadKey();
}
}
}
法2:
using System;
namespace 变量
{
class Program
{
static void Main(string[] args)
{
String name = "卡卡西";
int age = 30;
string email = "kakaxi@qq.com";
string address = "火影村";
decimal salary = 5000m;
Console.WriteLine("我叫{0},我今年{1}岁了,我住在{2},我的邮箱是{3},我的工资是{4}", name, age, address, email,salary);
Console.ReadKey();
}
}
}
结果都是:
第2题:定义一个变量存储一个人的年龄(18),然后发现这个人的年龄不是18岁,要把这个人的年龄改成81岁(本题体会变量可以被重复多次赋值),最后把这个人的年龄输出到屏幕上?
using System;
namespace 练习题2
{
class Program
{
static void Main(string[] args)
{
int age = 18;
age = 81;
Console.WriteLine("原来你都" + age + "岁了呀");
Console.ReadKey();
}
}
}