c#第二天

using System;
/*
 类:数据成员+函数成员
 变量:存储的值可以变化
 定义一个变量
 数据类型关键字 变量名=xxx;
 变量先定义再使用,只能在其作用范围内使用,不能
 作用域:管辖范围{}
 常量 不可改变
 关键字 const


逻辑运算符 ||    &&    !
逻辑或:||  遇到一个真就为真
逻辑与:&&  遇到一个假就为假
逻辑非:! 取反


判断语句
一 单分支判断语句
if(条件)
{
条件为true执行的代码
}
 
二 双分支判断语句(二选一)
if(条件)
{
条件为true执行的代码
}
else
{
条件为false执行的代码
}
三多分支判断语句(多选一)
if(条件)
{
条件为true执行的代码
}
else if(条件2)
{
条件2为true执行的代码
}
....
else
{
以上条件都不满足时候执行的代码
}
四 判断语句的嵌套
只要满足以上的结构都可以嵌套,可以无限层的嵌套
if(条件)
{
    if(条件)
    {
        条件为true执行的代码
    }
    else
    {
        if(条件)
        {
            条件为true执行的代码
        }
    }
}
switch  开关语句
switch(整数变量/字符串变量/枚举变量)
case 值1:
break
case 值2:
break
default:
break;
*/

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            #region 第一题、1、从键盘输入某个同学的基本信息,如姓名,血型,性别,年龄,班级,分数等,打印该同学的这些相关信息。
            /*
            Console.Write("请输入你的姓名:");
            string name = Console.ReadLine();
            Console.Write("请输入你的血型:");
            string blood = Console.ReadLine();
            Console.Write("请输入你的性别:");
            string sex = Console.ReadLine();
            Console.Write("请输入你的年龄:");
            int age = int.Parse(Console.ReadLine());
            Console.Write("请输入你的班级:");
            int yourclass = int.Parse(Console.ReadLine());
            Console.Write("请输入你的分数:");
            float score = float.Parse(Console.ReadLine());
            Console.WriteLine("---------学生基本信息------");
            Console.WriteLine("姓名\t\t\t{0}\n血型\t\t\t{1}\n性别\t\t\t{2}\n年龄\t\t\t{3}\n班级\t\t\t{4}\n分数\t\t\t{5}",
                name,blood,sex,age,yourclass,score);

            Console.ReadKey();
            */
            #endregion

            #region 第二题2、输入一个正整数,判断该数是奇数还是偶数,请编程实现
            /*
            Console.Write("请输入一个正整数:");
            int item = int.Parse(Console.ReadLine());
            if(item%2==0)
            {
                Console.WriteLine("此正整数为偶数");
            }
            else
            {
                Console.WriteLine("此正整数为奇数");
            }
            Console.ReadKey();

            */
            #endregion

            #region 第三题3、从键盘输入三个成绩,对这些成绩进行从大到小排序输出,计算三个成绩的平均值,请编程实现。
            /*
            Console.WriteLine("请输入第一个成绩:");
            int firstscore = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第二个成绩:");
            int secondtscore = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第三个成绩:");
            int thirdscore = int.Parse(Console.ReadLine());
            int num = 0;
            if (firstscore > secondtscore)
            {
                if (firstscore > thirdscore)
                {
                    if (secondtscore > thirdscore)
                        Console.WriteLine("{0}>{1}>{2}", firstscore, secondtscore, thirdscore);
                    if (secondtscore < thirdscore)
                        Console.WriteLine("{0}>{1}>{2}", firstscore, thirdscore,secondtscore);
                }
                else
                {
                    //if(firstscore > thirdscore)
                       //Console.WriteLine("{0}>{1}>{2}", firstscore, thirdscore, secondtscore);
                    if(firstscore<thirdscore)
                       Console.WriteLine("{0}>{1}>{2}", thirdscore,firstscore, secondtscore);
                }

            }
            if (firstscore < secondtscore)
            {
                if (secondtscore > thirdscore)
                {
                    if (firstscore > thirdscore)
                        Console.WriteLine("{0}>{1}>{2}", secondtscore, firstscore,thirdscore);
                    if (firstscore < thirdscore)
                        Console.WriteLine("{0}>{1}>{2}", secondtscore, thirdscore, firstscore);
                }
                else
                {
                    //if (secondtscore < thirdscore)
                        //Console.WriteLine("{0}>{1}>{2}", thirdscore, secondtscore, firstscore);
                    if (secondtscore > thirdscore)
                        Console.WriteLine("{0}>{1}>{2}", thirdscore, firstscore, secondtscore);
                }
            }
            // 123  132  213  231  312  321*/
            #endregion
            
            #region 三个数比大小
            /*
            Console.WriteLine("请输入第一个成绩:");
            int score1 = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第二个成绩:");
            int score2 = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第三个成绩:");
            int score3 = int.Parse(Console.ReadLine());
            
            //  2   3   1    3   2  1   1  2  3
            if (score2 > score1)
            {
                int q = score1;
                score1 = score2;
                score2 = q;
            }
            if (score3 > score2)
            {
                int q = score2;
                score2 = score3;
                score3 = q;
            }
            
            if (score2 > score1)
            {
                int q = score2;
                score2 = score1;
                score1 = q;
            }
            
            Console.WriteLine("{0}>{1}>{2}", score1, score2, score3);
            */
            #endregion

            #region    整数相关的一些运算符
            int num1 = 1;
            int num2 = 2;
            //算数运算符
            //+.-.*./.%
            int result = num1 + num2;

            //对于某个值只是增加或减少,++,--可以放在变量前 也可以放在变量后
            result = 1;
            result++;
            int b = ++result; //++放在后面,先赋值再++ ;  ++放在前面,先++再赋值
            const float a = 3.1f;
            #endregion

            #region  控制台输入一个三位数的整数,输出每一位的值,并且从小到大排序输出。
            /*
            Console.WriteLine("请输入一个三位数:");

            int num = int.Parse(Console.ReadLine());

            int numone = num / 100;
            int numtwo = (num / 10) % 10;
            int numthree = num % 10;
            Console.WriteLine("第一位{0}第二位{1}第三位{2}", numone, numtwo, numthree);
            if(numone > numtwo)
            {
                int w = numone;
                numone = numtwo;
                numtwo = w;
            }
            if(numtwo>numthree)
            {
                int w = numtwo;
                numtwo = numthree;
                numthree = w;
            }
            if(numone>numtwo)
            {
                int w = numone;
                numone = numtwo;
                numtwo = w;
             }
            Console.WriteLine("{0}{1}{2}",numone,numtwo,numthree);

            */
            #endregion

            #region 输入两个整数获取最大值
            /*
            Console.WriteLine("请输入第一个整数:");
            int num4 = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第二个整数:");
            int num5 = int.Parse(Console.ReadLine());
            if (num4 > num5)
            {
                Console.WriteLine("最大值为:" + num4);
            }
            else
            {
                Console.WriteLine("最大值为:" + num5);
            }
            */
            #endregion

            #region switch语句
            //小括号中是一个表达式或者变量(整数,枚举,字符串)或者表达式
            //多选一
            int r = 3;
            switch (r)
            {
                case 1:
                    Console.WriteLine("哈");
                    break;
                case 2:
                case 3:
                    Console.WriteLine("哈哈/哈哈哈");
                    break;
            }
            #endregion


            Console.ReadKey();
        }
    }
}

字符     int n = '3' + '4';
            char c = (char)n;
            Console.WriteLine(c);

1.将单个字符的字符串转化成ASCII码字符串

string str1="a";

byte[] array = System.Text.Encoding.ASCII.GetBytes(str1);

int asciicode = (int)(array[0]);

string ASCIIstr1= Convert.ToString(asciicode);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值