第五十九课 变量的作用域
1. 变量的作用域是向内的不能向外。如果在变量所在的域中还有下一个域,那么也起作用,如果在所在的域外,那么就不起作用了。
2.在不同作用域中变量是可以重复的,如果在同一个作用域中则不可以重复的。
3.for( int j = 0 ; j < 10 ; j++ )
{
}
int j = 0;这个变量时在for内的,属于for域之内的。
第五十九课 变量的作用域
1. 变量的作用域是向内的不能向外。如果在变量所在的域中还有下一个域,那么也起作用,如果在所在的域外,那么就不起作用了。
2.在不同作用域中变量是可以重复的,如果在同一个作用域中则不可以重复的。
3.for( int j = 0 ; j < 10 ; j++ )
{
}
int j = 0;这个变量时在for内的,属于for域之内的。
第五十八课 for循环的其它情况
1. for循环:
for( 初始条件;条件判断;递增 )
{
循环体;
}
for括号内的三个条件都可以不写,初始条件和递增都可以写在其他地方,条件判断如果不写默认为true。
for语句的{}可以省略,估计也和if语句一样,只执行接下来的一条。
2. break只跳出所在的循环。
int i =1;
for( ; ; )
{
Console.WriteLine( i );
i++;
if ( i>10 )
{
break;
}
}
第五十七课 do...while循环
1. do...while语句结构
do{
循环体
}while( 条件判断 );
循环体在前,条件判断在后。
2.do...while与while的区别:
do...while先执行一次循环体,最后在判断漫步满足条件,就是至少要执行一次循环体。
while先判断满不满足条件,如果满足就执行循环体,知道条件不满足以后跳出循环。
1、判断对错:××√××√;
2、第1题:
第2题:C;
第3题:
第4题:

第5题:D

第6题:

第7题:

1、转译字符‘\’;
2、字符串换行:‘\n’;
1、单行注释://;
2、多行注释:/* */;
3、ctrl+k ctrl+c 快速注释;
4、Ctrl+k ctrl+U 快捷取消注释;
1、Using System 引入命名空间;
2、namesoace 命名空间;
3、class 类;
4、Main 方法;
1、背景选深色;
2、字体选‘Jet Brains Mono’‘Consolas’;
第一季:编程基础
C#-001
1.主要内容:
(一)变量
(二)分支语句 if switch
(三)字符串
(四)数组
2.学习方法:
多练习、百度谷歌辅助学习、leetcode、⽜客⽹
runnoob菜鸟
第五十六课 for循环训练
1. 设定初始化和条件判断语句的取值范围:
①当递增用于步骤使用时,可以从0到指定的最高值
比如说老师出的题目中,要输出20个星号。
②当递增用于数字统计时,可以从1到指定的最高值+1。
(小提示而已,不是全部情况都这样的,初学小白的笔记而已,嘿嘿!)
2.输入两个正整数n和m,计算n和m之间(包含n和m)所有能被17整除的数的和,并输出和。
int n=Convert.ToInt32(Console.ReadLine());
int m=Convert.ToInt32(Console.ReadLine());
int temp = 0;
int b = 0;
if (n > m)
{
temp = n;
n = m;
m = temp;
}
for (int a = n; a < m+1; a++)
{
if (a % 17 == 0)
{
b += a;
}
}
Console.Write(b);
3.输入两个正整数n和m,利用for循环打印出来n和m之间(包含n和m),所有的级数和所有的偶数。奇数和偶数各方在一行并用空格分隔。
int n=Convert.ToInt32(Console.ReadLine());
int m=Convert.ToInt32(Console.ReadLine());
int temp = 0;
string ji = "";
string ou = "";
if (n > m && n > 0 && m > 0)
{
temp = n;
n = m;
m = temp;
}
for(int a =n; a <= m; a++)
{
if (a % 2 == 1 )
{
ji += a + " ";
}
else
{
ou += a + " ";
}
}
Console.WriteLine(ji);
Console.Write(ou);
注:
string chuan ="";
表示字符串变量chuan为空,好比int a = 0;(自己猜想的哦),
chuan += a+" ";
表示,想chuan变量里放入字符串并用空格隔开,可以放很多个,不会被覆盖,而是被组拼起来形成一个串。(给自己串饿了,想起啤酒来了,走了,出去吃串喝啤酒去)
第五十五课 通过for循环输出1-10
1. for语句:
for( 初始化; 条件判断; 增量表达式 )
{
循环体;
}
注:
初始化只执行一次;
条件判断执行到不满足条件为止;
增量表达式在循环体执行完以后执行;
然后再执行条件判断→循环体→增量表达式......→条件判断不满足跳出循环。
2. 条件判断语句的书写时,相同条件表达,性能不同:
i<11;
i<=10;
表达相同,性能不同。1<11;更快一些,每一步只有一次判断;i<=10;慢有一些,每一步要两次判断。
sda
第五十四课 编程题while循环
1. 班上有若干名学生,输入学生的个数,然后输入每一个学生的年龄,计算出来平均年龄,保留到小数点后两位,输出平均年龄。
int mub=Convert.ToInt32(Console.ReadLine());
int temp = 0;
double count = 0;
while (temp< mub)
{
int a = Convert.ToInt32(Console.ReadLine());
count += a;
temp++;
}
double pj = 1.0*count /mub;
double d = ((int)(pj * 100)) / 100.0;
Console.WriteLine("学生的平均年龄为:"+d);
可修改为老师的方法:
int mub=Convert.ToInt32(Console.ReadLine());
int temp = 0;
double count = 0;
while (temp< mub)
{
int a = Convert.ToInt32(Console.ReadLine());
count += a;
temp++;
}
double pj = 1.0*count /mub;
pj = ((int)(pj * 100)) / 100.0;
Console.WriteLine("平均年龄为:"+pj);
2. Console.WrtieLine();
表示输出并换行,是先输出再换行。
例如:
Console.Wrtie(1);
Console.Wrtie(2);
Console.WrtieLine(3);
Console.Wrtie(4);
输出结果为:
123
4
3再同一行,表示WriteLine功能是先输出并换行。
3.单独使用Console.WriteLine();
只起到换行的作用,不输出任何值。
第五十三课 编程题3n加1问题
1. 3n+1问题:
对于任意大于1的自然数n,若n为奇数,将n变成3n+1,否则变成n的一半,经过若干次这样的变化,n最终一定会变成1,。比如:7→22→11→34→17→52→26→13→40→20→10→5→16→8→4→2→1
输入n,输出变换的次数。
比如输入3,输出7;输入10,输出6。
int n =Convert.ToInt32(Console.ReadLine());
int a = 0;
while (n > 1)
{
if(n % 2 == 1)
{
n = 3 * n + 1;
a++;
}
else
{
n = n / 2;
a++;
}
}
Console.Write("最后值为{0}" + " " + "共用{1}步", n, a);
这道题还蛮好玩的,睡觉去了,睡晚了更掉头发,明天再听老师揭秘。
注:
计循环次数额a++写在while里if外啊,我还每个if里面写一个,真笨。
public class Program
{
public static void Main(string[] args)
{
//题目1:有⼀个游乐场,只有年龄不⼤于16岁的⻘少年可以进⼊,判断输⼊的年龄是否符合条件
Console.WriteLine("请输入年龄");
int age = Convert.ToInt32(Console.ReadLine());
if ((age > 0)&&(age <= 16))
{
Console.WriteLine("能进去");
}
else
{
Console.WriteLine("不可以");
}
Console.ReadKey();
}
}
//输⼊考试成绩(0-100),
//如果90-100,评级为A
//如果70-89,评级为B
//如果60-69,评级为C
//如果⼩于60,评级为D,
//根据输⼊的成绩,输出评级
Console.WriteLine("请输入成绩");
int score = Convert.ToInt32(Console.ReadLine());
//double age2 = age % 2;
Console.WriteLine("读取成功:您的成绩为"+score);
if (score >= 0 && score<=60)
{
Console.WriteLine("D级的垃圾,爪巴");
}
else if (score >= 60 && score<= 69)
{
Console.WriteLine("C级的垃圾,爪巴");
}
else if (score >= 70 && score <= 89)
{
Console.WriteLine("B级的垃圾,爪巴");
}
else if (score >= 90 && score <= 100)
{
Console.WriteLine("A级的垃圾,爪巴");
}
else
{
Console.WriteLine("神经病,能不能好好填成绩?");
}
Console.ReadKey();
驼峰(Camel)命名法
第五十二课 控制while循环的开头和结尾
1. 输入两个整数n1,n2,输出n1-n2(包含n1和n2)之间所有的偶数。
int n1 = Convert.ToInt32(Console.ReadLine());
int n2 = Convert.ToInt32(Console.ReadLine());
if (n1 > n2)
{
int temp = n1;
n1 = n2;
n2 = temp;
Console.WriteLine("{0}、{1}", n1, n2);
}
while (n1 < n2 + 1)
{
if (n1 % 2 == 0)
Console.Write(n1+" ");
n1++;
}
学这玩应掉头发!
2. 3n+1问题:
对于任意大于1的自然数n,若n为奇数,将n变成3n+1,否则变成n的一半,经过若干次这样的变化,n最终一定会变成1,。比如:7→22→11→34→17→52→26→13→40→20→10→5→16→8→4→2→1
输入n,输出变换的次数。
比如输入3,输出7;输入10,输出6。
int n =Convert.ToInt32(Console.ReadLine());
int a = 0;
while (n > 1)
{
if(n % 2 == 1)
{
n = 3 * n + 1;
a++;
}
else
{
n = n / 2;
a++;
}
}
Console.Write("最后值为{0}" + " " + "共用{1}步", n, a);
这道题还蛮好玩的,睡觉去了,睡晚了更掉头发,明天再听老师揭秘。
第五十课 while循环的调节书写
1. int Hp = 100;
while (Hp>0)
{
Hp -=3;
Console.WriteLine("Hp");
}
注:
Hp--;表示递减1.
Hp -= 3;递减3就是这么写。
第四十九课 while循环的基本结构
while(满足true执行,flase终止)
{
循环语句
}