[csharp]
//Random隨機數
Random r = new Random();
while (true)
{
int i = r.Next(1, 7);
Console.WriteLine(i);
Console.ReadKey();
}
//指定分隔符數組,返回不帶空格符的字符串
string str = "my name is lei";
char[] a = { ' ' };
string[] b = str.Split(a,StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < b.Length; i++)
{
Console.WriteLine(b[i]);
}
Console.ReadKey();
//倒序輸出
Console.WriteLine("請輸入字符串");
string a = Console.ReadLine();
string[] d = a.Split(' ');
for (int i = d.Length - 1; i >= 0;i-- )
{
Console.Write(d[i]+" ");
}
Console.ReadKey();
//忽略大小寫
string a = "a";
string b = "A";
if (a.Equals(b,StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("一樣的");
}
else { Console.WriteLine("不一樣"); }
Console.ReadKey();
//字符替換
string a = "2008-11-12";
string[] b = a.Split('-');
Console.WriteLine("{0}年{1}月{2}日", b);
Console.ReadKey();
//九九乘法表
for (int i = 1; i <= 9;i++ )
{
for (int j = 1; j <= i;j++ )
{
Console.Write("{0}X{1}={2:00} ",i,j,i*j);
}
Console.WriteLine();
}
Console.ReadKey();
//判斷字符串內是否有指定的子字符串
string[] strc = { "xxoo", "TMD", "和諧" };
string a = Console.ReadLine();
int i;
for (i = 0; i < a.Length; i++)
{
if (a.Contains(strc[i]))
{
break;
}
}
if (i < a.Length)
{
Console.WriteLine("有非法字符");
}
else
{
Console.WriteLine("合法");
}
//水仙花規則
//int i = 1 * 1 * 1 + 5 * 5 * 5+3 * 3 * 3;
//求100_999的水仙花數
for (int i = 100; i <= 999;i++ )
{
//把個 十 百 分離出來
int ge=i%10;
int shi=i/10%10;
int bai=i/100;
//按照水仙花數規則判斷
if(i==ge*ge*ge+shi*shi*shi+bai*bai*bai )
{
Console.WriteLine(i);
}
}
Console.ReadKey();
// 求1_100直接的偶數和
int sum = 0;
for (int i = 1; i <= 100;i++ )
{
//如果i能被2整除說明這個數是偶數
if(i%2www.2cto.com
==0)
{ += i;
Console.WriteLine(i);
}
}
Console.WriteLine(sum);
Console.ReadKey();
}