using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
//判斷變量a與存放數(shù)值10的關(guān)系
Console.WriteLine("請輸入數(shù)值判斷與10的關(guān)系.");
int a;
try
{
a = int.Parse(Console.ReadLine());
}
catch { a = 0; }
if (a < 10)
{
Console.WriteLine("a小于10");
}
if (a == 10)
{
Console.WriteLine("a等于10");
}
if (a > 10)
{
Console.WriteLine("a大于10");
}
//輸入一周中的第幾天
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("請輸入1-7中的一個數(shù)字");
int week = int.Parse(Console.ReadLine());
if (week == 1) { Console.WriteLine("星期一"); }
if (week == 2) { Console.WriteLine("星期二"); }
if (week == 3) { Console.WriteLine("星期三"); }
if (week == 4) { Console.WriteLine("星期四"); }
if (week == 5) { Console.WriteLine("星期五"); }
if (week == 6) { Console.WriteLine("星期六"); }
if (week == 7) { Console.WriteLine("星期日"); }
//1.switch break 結(jié)束當前代碼體
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("請輸入星期");
switch (week)
{
case 1: Console.WriteLine("星期一"); break;
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: Console.WriteLine("您的輸入有誤"); break;
}
//判斷2016年每個月份天數(shù)
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("請輸入月份");
int month = int.Parse(Console.ReadLine());
switch (month)
{
case 1: Console.WriteLine("本月28"); break;
case 2:
case 3:
case 4:
Console.WriteLine("本月29"); break;
default: Console.WriteLine("您的輸入有誤"); break;
}
//2.三元運算
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("請輸入數(shù)字,判斷于10的關(guān)系");
int num = int.Parse(Console.ReadLine());
string str = num < 10 ? "小于10" : "大于10";
Console.WriteLine(str);
//3.While
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("輸出1-50");
int cnum = 0;
while (cnum < 50)
{
cnum++;
Console.WriteLine(cnum);
}
//4.Do While
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("輸出1-50");
cnum = 0;
do
{
cnum++;
Console.WriteLine(cnum);
} while (cnum < 50);
//5.for
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("輸出100-110");
for (int i = 100; i < 110; i++)
{
Console.WriteLine(i);
}
Console.WriteLine("====================九九乘法表===================");
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0}×{1}={2} ", j, i, j * i);
if (j * i < 10)
{
Console.Write(" ");
}
}
Console.WriteLine();
}
//6 foreach string類型可以看成char類的一個集合
//將語句識別為單詞并逐行輸出
string name = "my name is zhu";
foreach (char s in name)
{
//char.IsWhiteSpace( )判斷是否為空格
if (char.IsWhiteSpace(s))
{
Console.WriteLine();
}
else
{
Console.WriteLine(s);
}
}
Console.ReadKey();
}
}
}
聯(lián)系客服