菜鸟每天练习 之 99乘法 switch 判断字符

99乘法:

static void Main() { Console.WriteLine("九九乘法表:"); for (int i = 1; i <= 9;i++ ) { for (int j = 1; j <= i;j++ ) { Console.Write("{0}*{1}={2}/t",i,j,i*j); } Console.WriteLine();//换行 } Console.ReadKey(); }

 

 

switch:

static void Main(string[] args) { Console.WriteLine("请选择你需要的奶茶:1=(大杯:10¥),2=(中杯:8¥),3=(小杯:5¥)"); int n = int.Parse(Console.ReadLine()); switch(n) { case 1: Console.WriteLine("大杯,请付10¥"); break; case 2: Console.WriteLine("中杯,请付8¥"); break; case 3: Console.WriteLine("小杯:5¥"); break; default: Console.WriteLine("你还想不想买"); break; } Console.ReadKey(); }

 

 

判断字符:

static int Main(string[] args) { Console.WriteLine("please input a string:"); char chleter =Convert.ToChar(Console.ReadLine().Substring(0,1)); if(chleter>='A') { if(chleter<='Z') { Console.WriteLine("{0} is big char",chleter); Console.ReadKey(); return 0; } } if(chleter >='a' && chleter<='z') { Console.WriteLine("{0} is small char", chleter); Console.ReadKey(); return 0; } if(char.IsDigit(chleter)) { Console.WriteLine("{0} is data",chleter); Console.ReadKey(); return 0; } Console.WriteLine("{0} is special",chleter); Console.ReadKey(); return 1; }

 

你可能感兴趣的:(基础练习)