判斷成績:1
class Program
{
static void Main(string[] args)
{
string x;
int y;
Console.Write("請輸入考試成績:");
x = Console.ReadLine();
y = Int32.Parse(x);
if (y < 60)
{
Console.WriteLine("恭喜您,您沒有通過本次考試!您的考試成績爲:{0}分", x);
Console.ReadLine();
}
else
{
Console.WriteLine("很遺憾您通過了本次考試,您的成績爲:{0}分", x);
Console.ReadLine();
}
}
}
}
class Program
{
static void Main(string[] args)
{
string x;
int y;
Console.Write("請輸入考試成績:");
x = Console.ReadLine();
y = Int32.Parse(x);
if (y < 60)
{
Console.WriteLine("恭喜您,您沒有通過本次考試!您的考試成績爲:{0}分", x);
Console.ReadLine();
}
else
{
Console.WriteLine("很遺憾您通過了本次考試,您的成績爲:{0}分", x);
Console.ReadLine();
}
}
}
}
判斷姓名是否:2
namespace aa
{
class Program
{
static void Main(string[] args)
{
string name;
Console.Write(" 請輸入你的用戶名:");
name = Console.ReadLine();
if (name == "grant")
{
Console.WriteLine("歡迎{0}回來!!!", name);
Console.ReadKey();
}
{
if (name != "grant")
Console.WriteLine("不好意思你不是她,請叫來過來輸入名字,哈哈!!!");
Console.ReadLine();
}
}
}
}
{
class Program
{
static void Main(string[] args)
{
string name;
Console.Write(" 請輸入你的用戶名:");
name = Console.ReadLine();
if (name == "grant")
{
Console.WriteLine("歡迎{0}回來!!!", name);
Console.ReadKey();
}
{
if (name != "grant")
Console.WriteLine("不好意思你不是她,請叫來過來輸入名字,哈哈!!!");
Console.ReadLine();
}
}
}
}
檢查輸入字符是小寫還是大寫或是數字:3
namespace aa
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入一個字符");
char a = (char)Console.Read();
string b;
if (char.IsUpper(a))//判斷大寫字母
{
b = "請輸入你的字符是大寫啊哈哈!!!";
}
else if (char.IsLower(a))//判斷小寫字母
{
b = " 請輸入你的字符是小寫啊,哈哈!!!";
}
else if (char.IsNumber(a))//判斷你的數字
{
b = "請輸入你的數字啊,哎不要輸入錯啊!!哈哈!!!";
}
else
b = "你輸入的即不是大寫字符,也不是小寫字母,也不是數字啊!搞好了輸入!!!";
Console.WriteLine(b);
Console.ReadKey();
}
}
}
namespace aa
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入一個字符");
char a = (char)Console.Read();
string b;
if (char.IsUpper(a))//判斷大寫字母
{
b = "請輸入你的字符是大寫啊哈哈!!!";
}
else if (char.IsLower(a))//判斷小寫字母
{
b = " 請輸入你的字符是小寫啊,哈哈!!!";
}
else if (char.IsNumber(a))//判斷你的數字
{
b = "請輸入你的數字啊,哎不要輸入錯啊!!哈哈!!!";
}
else
b = "你輸入的即不是大寫字符,也不是小寫字母,也不是數字啊!搞好了輸入!!!";
Console.WriteLine(b);
Console.ReadKey();
}
}
}
Do…while循環語句:4
namespace grant
{
class Program
{
static void Main(string[] args)
{
int n = 1;
do
{
Console.WriteLine(n);
n++;
}
while (n < 100);
Console.ReadKey();
}
}
}
while (n < 100);
Console.ReadKey();
}
}
}
判斷數字對應的星期:5
namespace grant
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("對應表:1=星期一,2=星期二,3=星期三");
Console.Write("按照上面對應輸入數字:");
string a;
int b;
a = Console.ReadLine();
b = int.Parse(a);
string c;
switch (b)
{
case 1:
c = "星期一";
break;
case 2:
c = "星期二";
break;
case 3:
c = "星期三";
break;
default:
c = "你輸的什麼東東啊";
break;
}
Console.WriteLine("請輸入你的字符:{0},對應的日期:{1}", b, c);
Console.ReadLine();
}
}
}
namespace grant
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("對應表:1=星期一,2=星期二,3=星期三");
Console.Write("按照上面對應輸入數字:");
string a;
int b;
a = Console.ReadLine();
b = int.Parse(a);
string c;
switch (b)
{
case 1:
c = "星期一";
break;
case 2:
c = "星期二";
break;
case 3:
c = "星期三";
break;
default:
c = "你輸的什麼東東啊";
break;
}
Console.WriteLine("請輸入你的字符:{0},對應的日期:{1}", b, c);
Console.ReadLine();
}
}
}
Foreach循環::6
namespace grant
{
class Program
{
static void Main(string[] args)
{
char[] x = new char[] { 'g','r','n', 't', 'g', 'r','a', 't'};//定義數組x
namespace grant
{
class Program
{
static void Main(string[] args)
{
char[] x = new char[] { 'g','r','n', 't', 'g', 'r','a', 't'};//定義數組x
foreach (char y in x)//數組中的值賦予char類型變量y,並按照數組中的次數循環輸出
{
Console .WriteLine (x);
}
Console.WriteLine ();//輸出
Console.ReadLine();//定 //呵呵!!!
}
}
}
{
Console .WriteLine (x);
}
Console.WriteLine ();//輸出
Console.ReadLine();//定 //呵呵!!!
}
}
}
數組的length屬性:7
namespace grant
{
class Program
{
static void Main(string[] args)
{
int[]s={0,1,2,3,4,5,6,7,8};
int x=s.Length ;
Console.WriteLine("s數組爲{0}", x);
Console.ReadLine ();
}
}
}