using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _13.流程控制之if语句
{
class Program
{
static void Main(string[] args)
{
/**
* if语句语法及执行过程:
* if ()
* {
* is true>
* }
* else if ()
* {
* is true>
* }
* ...
* else
* {
* is false>
* }
*
*/
// 求三个整数中的最大值
// if语句版本
{
int a = 6, b = 5;
string comparison = null;
if (a > b)
comparison = "greater than";
if (b > a)
comparison = "less than";
if (a == b)
comparison = "equal to";
Console.WriteLine("{0} is {1} {2}", a, comparison, b);
}
// if_else语句版本
{
int a = 6, b = 5;
string comparison = null;
if (a > b)
{
comparison = "greater than";
}
else
{
if (a < b)
comparison = "less than";
else
comparison = "equal to";
}
Console.WriteLine("{0} is {1} {2}", a, comparison, b);
}
// if_elseif_else语句版本
{
int a = 6, b = 5;
string comparison = null;
if (a > b)
{
comparison = "greater than";
}
else if (a < b)
{
comparison = "less than";
}
else
comparison = "equal to";
Console.WriteLine("{0} is {1} {2}", a, comparison, b);
}
Console.ReadKey();
}
}
}
当前题目:十三、流程控制之if语句
当前路径:
http://cdweb.net/article/gdjpii.html