class Program
{
static void Main(string[] args)
{
int[] sort ={ 9, 3, 1, 5, 7, 8, 0, 4, 6, 2 };
Console.Write("排序前:");
for (int i = 0; i < sort.Length;i++ )
{
Console.Write("{0} ", sort[i]);
}
bool IsSort = true;
int temp = 0;
while (IsSort)
{
IsSort = false;
for (int i = 0; i < sort.Length - 1; i++)
{
if (sort[i + 1] < sort[i])
{
temp = sort[i];
sort[i] = sort[i + 1];
sort[i + 1] = temp;
IsSort = true;
}
} }
Console.Write("排序后:");
for (int i = 0; i < sort.Length; i++)
{
Console.Write("{0} ", sort[i]);
}
}
}
这样只是对已经确定好的int数组进行排序,如何调整为键盘输入一串数字呢
是否string s =Console.ReadLine();
char[] char1 = s.ToCharArray()
那怎么在转为int[]呢
望大家帮小弟谢谢
{
static void Main(string[] args)
{
int[] sort ={ 9, 3, 1, 5, 7, 8, 0, 4, 6, 2 };
Console.Write("排序前:");
for (int i = 0; i < sort.Length;i++ )
{
Console.Write("{0} ", sort[i]);
}
bool IsSort = true;
int temp = 0;
while (IsSort)
{
IsSort = false;
for (int i = 0; i < sort.Length - 1; i++)
{
if (sort[i + 1] < sort[i])
{
temp = sort[i];
sort[i] = sort[i + 1];
sort[i + 1] = temp;
IsSort = true;
}
} }
Console.Write("排序后:");
for (int i = 0; i < sort.Length; i++)
{
Console.Write("{0} ", sort[i]);
}
}
}
这样只是对已经确定好的int数组进行排序,如何调整为键盘输入一串数字呢
是否string s =Console.ReadLine();
char[] char1 = s.ToCharArray()
那怎么在转为int[]呢
望大家帮小弟谢谢
string str = Console.ReadLine();
string[] s = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int[] sort = new int[s.Length];
try
{
for (int i = 0; i < s.Length; i++)
{
sort[i] = Convert.ToInt32(s[i]);
}
}
catch { Console.WriteLine("输入有误"); }
//---排序
有些地方还不能理解 刚接触(不好意思)。不过认真看了前辈的内容后得到启发
string s=console.ReadLine();
int[] sort=new int[s.length];
foreach(int i in s.length)
{
sort[i]=convert.int32(s[i])-48;
Console.Write("{0} ", sort[i]);
}
...
...