关系运算符
>
<
>=
<=
==
!=
关系运算符是用来描述两个事物之间的关系
bool类型
在c#中我们用bool类型来描述对或者错
Bool类型的值只有两个 一个true 一个false
using System; namespace bool类型 { class Program { static void Main(string[] args) { bool a = 1500 >= 1; bool b = 12 > 12000; Console.WriteLine(a); Console.WriteLine(b); Console.ReadKey(); } } }
逻辑运算符
&& 逻辑与
||逻辑或
!逻辑非
由逻辑运算符连接的表达式叫做逻辑表达式
逻辑运算符两边放的一般都是关系表达式或者bool类型的值
复合赋值运算符
int number=10;
+=
number+=20;
number=number+20
-=
*=
/=
%=
using System; namespace 赋值运算符 { class Program { static void Main(string[] args) { int n=100; n = 1000;//给变量重新赋值,一旦给变量重新赋值,那么老值就不存在了,取而代之的是新值 Console.WriteLine(n); Console.ReadKey(); } } }
两道作业题
using System; namespace 两道作业题 { class Program { static void Main(string[] args) { //一共47天,用计算显示出有几周零几天 //int days = 47; //int weeks = days / 7; //int day = days % 7; //Console.WriteLine("{0}天是{1}周零{2}天",days,weeks,day); //Console.ReadKey(); //编程实现107653秒是几天几小时几分几秒? //int sum = 107653; //int oneDay = 60 * 60 * 24; //int oneHour = 60 * 60; //int oneMin = 60; //int day = sum / oneDay ; //int hour = (sum - day * oneDay ) / oneHour ; //int min = (sum - day * oneDay - hour * oneHour) / oneMin; //int sec = sum - day * oneDay - hour * oneHour - min * oneMin ; //Console.WriteLine("{0}秒是{1}天{2}小时{3}分钟{4}秒", sum, day, hour, min, sec); //Console.ReadKey(); int seconds = 107653; int days = seconds / 86400; int secs = seconds % 86400; int hours = secs / 3600; secs = secs % 3600; int min = secs / 60; secs = secs % 60; Console.WriteLine("{0}天,{1}时,{2}分,{3}秒", days, hours, min, secs); Console.ReadKey(); } } }