static void Main(string[] args)
{
// 根據用戶輸入字符串,輸出大寫字母有幾個,小寫字母有幾個。
Console.WriteLine("請輸入一行英文代碼");
string s = Console.ReadLine(); //用一個字符串接受輸入值。
int i = 0;
int j = 0;// i是大寫個數, j是小寫個數。
foreach (char s1 in s)
{
if (s1 >= 'A' && s1 <= 'Z')
{
i++;
}
else if(s1>='a'&&s1<='z')
{
j++;
}
continue; // 如果輸入的不是英文字母,則跳出循環。
}
Console.WriteLine("大寫字母有{0}個,小寫字母有{1}個。",i,j);
}
運行結果: