如何编写一个程序来查找 List 中的最大和最小分数?
Console.WriteLine("How many fractions to comapre?");
string nic = Console.ReadLine();
int amount = int.Parse(nic);
double min = 0; double max = 0;
for (int i = 0; i < amount; i++)
{
Console.WriteLine("Enter fraction to compare. WRITE AS IMPROPER FRCATION");
string str = Console.ReadLine();
string[] each = str.Split('/');
List<double> eachDoub = new List<double> { };
foreach (string hit in each)
{
eachDoub.Add(double.Parse(hit));
}
List<double> finals = new List<double> { };
foreach (double hit in eachDoub)
{
finals.Add(eachDoub[0] / eachDoub[1]);
}
max = finals.Max();
min = finals.Min();
}
Console.WriteLine("The maximum is {0} and the minimum is {1}.", max, min);
Console.ReadLine();
输入:要比较多少分数?3
输入分数
4/1 输入分数
3/1
当我运行这个程序时,它不能正常工作,它只会打印为最小值和最大值输入的最后一个值。我怎样才能解决这个问题?