C#第四章学习代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._1_表达式
{
    class Program
    {
        static void Main(string[] args)
        {
            //int a = 10;
            //int b = 5;
            //int c = a + b;
            //Console.WriteLine(c);
            //Console.ReadKey();

            Console.WriteLine("请输入您的语文成绩");
            double Chinese = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("请输入您的数学成绩");
            double math = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("您的总分是{0}分,您的平均分是{1}分",math+Chinese,(math+Chinese)/2);
            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._2数学运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            //int a = 5;
            //int b = 3;
            //int c = a %b;
            //int d = +a;
            //int e = -a;
            ////double    d = 5.0;
            ////double e = 3.0;
            ////double f = d/ e;
            //Console.WriteLine("d的值是{0},e的值是{1}",d,e);

            int var1 = 10;
            int var2;
            var2 = var1++;//var2=10,var1=11
            Console.WriteLine(var1);
            Console.WriteLine(var2);


            var2 = ++var1;//var1=12 var2=12
            Console.WriteLine(var1);
            Console.WriteLine(var2);



            Console.ReadKey();            
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._3赋值运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            int var1 = 10, var2 = 7;
            var1 += var2;
            Console.WriteLine("var1 = 10, var2 = 7,那么var1+=var2的值是{0}", var1);
            var1 = 10;
            var2 = 7;
            var1 -= var2;
            Console.WriteLine("var1 = 10, var2 = 7,那么var1-=var2的值是" + var1);
            var1 = 10;
            var2 = 7;
            var1 *= var2;
            Console.WriteLine("var1 = 10, var2 = 7,那么var1*=var2的值是" + var1);
            var1 = 10;
            var2 = 7;
            var1 /= var2;
            Console.WriteLine("var1 = 10, var2 = 7,那么var1/=var2的值是" + var1);
            var1 = 10;
            var2 = 7;
            var1 %= var2;
            Console.WriteLine("var1 = 10, var2 = 7,那么var1%=var2的值是" + var1);



            Console.ReadKey();

        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._4关系运算符
{
    class Program
    {
        static void Main(string[] args)
        {

            bool mybool;
            int a = 5;
            int b = 3;
            mybool = a == b;
            Console.WriteLine(mybool);

            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._5布尔运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            bool var1 = true;
            bool var2 = true;
            Console.WriteLine(var1|var2);

            //int a = 10;
            //int b = 15;
            //Console.WriteLine((10==a++)||(16==b--));
            //Console.WriteLine("a的值是{0},b的值是{1}",a,b);
            //||运算符前一个操作数为true值时,不再计执行后一个操作数的内容



            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._6位运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1 = 4;
            int num2 = 1;
            Console.WriteLine(num1>>num2);
            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._7_其他运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            //string str1 = "我的名字叫";
            //string str2 = "雪上行者";
            //string str3 = str1 + str2;
            //Console.WriteLine(str3);
            //Console.WriteLine("我是用于输出到屏幕" + "这个是利用加号进行连接的");
            // Console.ReadKey();

            //int a = 10;
            //double b = 3.14;
            //string c = "我要自学网";
            //bool mybool = false;
            //mybool = a is int;
            //Console.WriteLine("a is int\t"+mybool);
            //mybool = b is double;
            //Console.WriteLine("b is double\t"+mybool);
            //mybool = c is string;
            //Console.WriteLine("c is string\t"+mybool);
            //Console.ReadKey();
            //// \t跳到下一个制表位

            //输出语句“I have 数量 pen”


            //Console.WriteLine("请输入您拥有的钢笔数量");
            //int qty = Convert.ToInt32(Console.ReadLine());


            //Console.WriteLine("I have {0} pen{1}",qty,qty>1?"s":"");

            //判定用户输入的数字与5的关系

            Console.WriteLine("请您输入需要比较的数");
            int num = Convert.ToInt32(Console.ReadLine());
            string str=num>=5?"大于等于":"小于";
            Console.WriteLine("您输入的数字{0}5",str);

            Console.ReadLine();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._8运算符的优先级
{
    class Program
    {
        static void Main(string[] args)
        {
            int var1 = 3;
            bool mybool = false;
            mybool = (var1 <= 4) && (var1 >= 2);
            Console.WriteLine(mybool);
            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4._9本章小结及任务实施
{
    class Program
    {
        static void Main(string[] args)
        {
            //1232855秒是几天几小时几分几秒
            Console.WriteLine("请输入您想要计算的秒数");
            int time = Convert.ToInt32(Console.ReadLine());
            int day = time / (24 * 3600);
            int hour = time % (24 * 3600) / 3600;
            int min = time % 3600 / 60;
            int sec = time % 60;
            Console.WriteLine("{0}秒是{1}天{2}小时{3}分钟{4}秒",time,day,hour,min,sec);
            Console.ReadKey();

        }
    }
}

 

posted @ 2016-03-30 20:33  前缘Q+7589848  阅读(430)  评论(0编辑  收藏  举报