using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace secondlesson
{
class Program
{
static void Main(string[] args)
{
//一、布尔数据类型bool,占一个字节,表示真、假
//将int转成bool,非0都为true
//将bool转成int,true:1,false:0
//bool isDead = false;
//Console.WriteLine(isDead);
//int n = -200;
//Console.WriteLine(Convert.ToBoolean(n));
//二、关系运算符:>、<、>=、<=、==、!=
//int a1 = 10, a2 = 20;
//bool result = a1 > a2;
//result = a1 < a2;
//result = a1 >= a2;
//result = a1 <= a2;
//result = a1 == a2;
//result = a1 != a2;
//Console.WriteLine(result);
////三、逻辑运算符:&&、 || 、!
//int i = 3, j = 5, k = 7;
////1、逻辑与 &&,只有当运算符两侧都为真时,结果才为真
////否则结果为假
//bool result = (i < j) && (j == k);
//Console.WriteLine(result);
////2、逻辑或 ||,运算符两侧同时为假时,结果才为假,否则
////结果为真
//result = (j > k) || (j != k);
//Console.WriteLine(result);
////3、逻辑非 !,取反,真变假,假变真
//result = !(i != k);
//Console.WriteLine(result);
////思考:逻辑或短路,逻辑与短路现象
////逻辑或短路:a或b,如果a为false,则直接跳过b,定义为false
////逻辑与短路:a与b,如果a为true,则直接跳过b,定义为ture
////练习:从控制台输入3个数d,e,f,用逻辑运算符来判断d
////是否是最大的数,如果是就输出d为最大数,否则输出
////不是最大数
Console.WriteLine("请输入三个数");
string d = Console.ReadLine();
int a = Convert.ToInt32(d);
string e = Console.ReadLine();
int b = Convert.ToInt32(e);
string f = Console.ReadLine();
int c = Convert.ToInt32(b);
if (a > b && a > c) { Console.WriteLine("d为最大数"); }
else { Console.WriteLine("不是最大数"); }
//保证当前程序完成前不退出
Console.ReadKey();
}
}
}
网友评论