位运算妙用2

来源:互联网 发布:java实现dnf自动刷怪 编辑:程序博客网 时间:2024/05/16 18:56
        //判断奇数偶数   用一个数与00000001逻辑与运算,结果为1的是奇数,0是偶数        static void bb() {        qq: Console.WriteLine("请输入一个数字:");            int aa = 0;            string ss = Console.ReadLine();            if (!int.TryParse(ss, out aa))            {                Console.WriteLine("请输入一个正确的数字!");                Console.ReadKey();                goto qq;            }            else {                if ((aa & 1) == 0)                {                    Console.WriteLine("偶数");                }                else {                    Console.WriteLine("奇数");                }                Console.WriteLine("还要继续吗,继续请输Y");                if (Console.ReadLine().ToLower() == "y")                {                    goto qq;                }            }        }

0 0