hear
cry
What's wrong with you?
hurt
knee
hand
move
elbow
neck
cough
fever
stomachache
safety first
helmet
near
knife
hear
cry
What's wrong with you?
hurt
knee
hand
move
elbow
neck
cough
fever
stomachache
safety first
helmet
near
knife
c=4
7
16
16
12
变量:先声明,再使用
1.2 4
2.4 7 16 16 12
赋值规则 右边赋值给左边
赋值新数据 旧数据被清空
变量要先声明再使用
变量要先初始化再使用(读取)
字符使用‘’
字符串使用“”
c=4
c=7
c=16
a=16
a=12
变量先声明再使用。变量要先赋值才能使用,第一次赋值叫做初始化
变量要先声明再使用
或者要先初始化再使用
任务19:016-判断结果-练习
假设int a= 3 b=8; 下面的代码输出结果是什么?
1,11
2,a+b
3, 3+8
4, a+b38
5, a+b13
23 = a; 错误 变量不能数字命名
a = b+c;对
x+y=z;错
a=a+1;对
int a =1;
a= 3+7-2;
int b = 3;
b = b+ 1;// b = 4
c = 4
c = 7
c = 16
a = 16
a = 48
11
a+b
3+8
a+b38
a+b11
using System;
namespace _003_变量
{
class Program
{
static void Main(string[] args)
{
int total;
//赋值
total = 4;
//int a;
//a = 1;
//int b = 1;
int a = 1;
a = 3 + 7 - 2;
int b = 3;
b = b + 1;
Console.WriteLine(a);
Console.WriteLine(b);
int c;
c = 10;//初始化
c = 11;
Console.WriteLine(c);
//female male
char sex = 'f';
sex = 'm';
}
}
}
先声明再赋值
或者声明赋值一起
变量需要先声明再使用
例:
int c(声明)
int c=10(赋值、初始化)
Console.WriteLine(c)(使用)
赋值以后会清空数值
举例:double shenggao = 171.53
shenggao = 172.36+0.58
那么”shenggao就等于172.94“
int b = 3;
b = b+1;
那么”b就等于4“
int a = 4;
int b = 3;
int b = 0;
c = a;
c = a+b;
c = a * a;
a = a * a;
a = a*b;
变量需要先声明再使用,不让会报错
读取变量必须要赋值,不然会报错
第一次赋值称之为”初始化“
字符赋值需要使用单引号
4
7.
16
16
12
8
4
赋值的覆盖
4
7
16
16
12
初始化
x+y=z;错
#判断代码正确
23 = a;
//上面的代码是将a赋值到23内,赋值是左边变量名,右边数值,例如a = 23;所以错误
x+y=z;
//同上,右边赋值给左边但是颠倒,所以错误
a=a+1;
//变量a加上1顺序正确,所以正确
console.writeline(a);
;可以输出a变量
c=4
c=7
c=16
a=16
a=12