我想知道如何将用户输入显示为编号列表?例如
这是我到目前为止在设置数组和按字母顺序排序方面的问题,但是也希望按照上面的方式显示,并且无法在任何地方找到任何相关信息。提前谢谢。
//call method to sort array in alphabetical order
fillArraySort();
//call method to display in numbered list
//displayNumberedList();
}
/*declare the array
ask user for index (size of array) and store user input array*/
static void fillArraySort()
{
int a;
Console.WriteLine("How many inanimate object names do you wish to enter?");
a = int.Parse(Console.ReadLine());
int[] index = new int[a];
for (int i = 0; i < index.Length; i++)
{
Console.WriteLine("Enter name of object:");
index [i] = int.Parse(Console.ReadLine());
}
Array.Sort(index);
Console.WriteLine("The array sorted in alphabetical order is: ");
foreach (var i in index)
{
Console.WriteLine(i);
}
Console.WriteLine();
Console.ReadLine();
}
//static void displayNumberedList()
//{
//code
答案 0 :(得分:1)
试试这个:
a = {"one":(10, 11.25), "two":(11, 12.25), "three":(-12, 13.25)}
for x,y in a.iteritems():
print "Number is ",y[0]
if y[0] > 0:
print "Positive"
else:
print "Negative"
这给出了:
1. Jam 2. Tea 3. Something 4. Something else
答案 1 :(得分:0)
static void FillArraySort()
{
Console.WriteLine("How many inanimate object names do you wish to enter?");
int number = int.Parse(Console.ReadLine());
var array = new string[number];
for (int index = 0; index < number; index++)
{
var message = string.Format("Enter name of object {0}:", index + 1);
Console.WriteLine(message);
array[index] = Console.ReadLine();
}
Array.Sort(array);
Console.WriteLine();
Console.WriteLine("The array sorted in alphabetical order is:");
for (int index = 0; index < number; index++)
{
var item = array[index];
var message = string.Format("{0}. {1}", index + 1, item);
Console.WriteLine(message);
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}