1.昨天做C#练习题时,有个if(){},写条件时,“==”写成“=”;
2.题目:编写一个应用程序用来输入的字符串进行加密,对于字母字符串加密规则如下:
‘a’→’d’ ‘b’→’e’ ‘w’→’z’ ……
‘x’→’a’ ‘y’→’b’ ‘z’→’c’
‘A’→’D’ ‘B’→’E’ ‘W’→’Z’ ……
‘X’→’A’ ‘Y’→’B’ ‘Z’→’C’?
对于其他字符,不进行加密。
namespace _152
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入字符串,进行加密:");
string strOld = Console.ReadLine();
string strTemp = "";
for (int i = 0; i < strOld.Length; i++)
{
//Array[] strNew = new Array[strOld.Length];//不用数组,用上面的字符串strTtemp
if (strOld[i] >= 'a' && strOld[i] <= 'w')
{
//int num = Convert.ToInt32(strOld[i]);不用这样写
int num = strOld[i];
num = num + 3;
char temp = (char)num;//强制转换
//strNew[i] = temp; 不用数组,这个就不必了
strTemp += temp;
} else if (strOld[i] >= 'A' && strOld[i] <= 'W')
{
int num = strOld[i];
num = num + 3;
char temp = (char)num;
strTemp += temp;
}
else if (strOld[i]=='x' || strOld[i] == 'y'|| strOld[i] == 'z'|| strOld[i] == 'X'|| strOld[i] == 'Y'|| strOld[i] == 'Z')
{
int num = strOld[i];
num = num -23;
char temp = (char)num;
strTemp += temp;
}
else strTemp += strOld[i];
}
Console.WriteLine(strTemp);
Console.ReadKey();
}
}
}
输入一组数字,用空格隔开,排序 ,输出,冒泡排序法:
namespace _153
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入一组数字用空格间隔:");
string str = Console.ReadLine();
string[] strArray = str.Split(' ');
for (int i = 1; i <= strArray.Length-1; i++)//这里的i,是指挤泡次数,j是数组的index
{
for (int j = 0; j <strArray.Length-1-i+1; j++)//这里长度,一开始,也写错了
{
if (Convert.ToInt32(strArray[j]) > Convert.ToInt32(strArray[j +1]))//这里一开始也想错啦,应该是把最大的数挤到最后
{
string temp = strArray[j];//这里交换,一开始,写错啦
strArray[j] = strArray[j+1];
strArray[j+1] = temp;
}
}
}
foreach (var item in strArray)
{
Console.Write(item+ ' ' );
}
Console.ReadKey();
}
}
}