if选择分支语句
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace if分支语句
{
class Program
{
static void Main(string[] args)
{
#region
//if (表达式)
//{
// 表达式成立后执行的语句块
//}
//Console.WriteLine("说,你这次考试得的分数");
//int score = int.Parse(Console.ReadLine());
//if (score == 100)
//{
// Console.WriteLine("妈妈带你去游乐场");
//}
//Console.WriteLine("**************");
#endregion
#region
//1.判断一个数是都是偶数,如果是偶数那么就加1并打印
//判断一个数是否为偶数 就是判断该数能否被2整除 被2整除就意味着余数为0
//Console.WriteLine("输入一个整数");
//int num = int.Parse(Console.ReadLine());
////= 是赋值号 在计算机中 ==是等号
////if 后面的括号后没有分号 ;
//// 如果加了分号 那么就会在任何情况下都要执行大括号里面的代码
//if (num % 2 == 0)
//{
// //以下四行代码表示的结果都一样
// //num = num + 1;
// //num += 1;
// //num++;
// ++num;
// Console.WriteLine(num);
//}
//if (num<0)
//{
// Console.WriteLine(-1);
//}
#endregion
#region
//报3 如果3的倍数 那么就输出"过" 否则输出该数
//Console.WriteLine("请输入一个数字");
//int num2 = int.Parse(Console.ReadLine());
//if (num2%3 == 0)
//{
// Console.WriteLine("过");
//}
//else
//{
// Console.WriteLine(num2);
//}
#endregion
#region
//判断一个年份是否为闰年
//如果年份能被4整除并且不能被100整除 或者能被400整除的都是闰年
//满足闰年的条件:
// 能被4整除 并且不能被100整除
//能被400整除
//Console.WriteLine(" 请输入年份:");
//int year = int.Parse(Console.ReadLine());
//if ((year % 4 == 0 && year % 100 !=0)|| (year % 400 ==0))
//{
// Console.WriteLine("这是一个闰年");
//}
//else
//{
// Console.WriteLine("这是一个平年");
//}
#endregion
// num1 > num2 num1 == num2 num1<num2
Console.WriteLine("请输入第一个数字");
int fisrtNumber = int.Parse(Console.ReadLine());
Console.WriteLine("请输入第二个数字");
int secondNumber = int.Parse(Console.ReadLine());
if (fisrtNumber<secondNumber)
{
Console.WriteLine("第一个数小于第二个数");
}
else if (fisrtNumber == secondNumber)
{
Console.WriteLine("两个数相等");
}else
{
Console.WriteLine("第一个数大于第二个数");
}
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
switch选择分支语句
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace switch讲解
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入一个数字");
int number = int.Parse(Console.ReadLine());
switch (number) //这里的表达式结果可以是 bool char string integer enum null
{
case 1:
Console.WriteLine("今天星期一");
break; //跳出当前的switch
case 2:
Console.WriteLine("今天星期二");
break;
case 3:
Console.WriteLine("今天星期三");
break;
case 4:
Console.WriteLine("今天星期四");
break;
case 5:
Console.WriteLine("今天星期五");
break;
case 6:
Console.WriteLine("今天星期六");
break;
case 7:
Console.WriteLine("今天星期七");
break;
default: //类似于else 只有在以上的7中情况都不满足的时候才执行
Console.WriteLine("你是地球人么?");
break;
}
Console.WriteLine("输入季节");
string season = Console.ReadLine();
switch (season)
{
case "春天":
Console.WriteLine("白衬衣");
break;
case "夏天":
Console.WriteLine("超短裙");
break;
case "秋天":
Console.WriteLine("夹克");
break;
case "冬天":
Console.WriteLine("羽绒服");
break;
default:
Console.WriteLine("你是地球人么?");
break;
}
}
}
}