如何在循环中正确使用数组
static void Main(string[] args)
{
Temp t = new Temp( 100,52,98,30,11,54,87);
Console.WriteLine(t.lowest());
}
public class Temp
{
private int[] temp = new int[7]; // array
public Temp(int d1, int d2, int d3, int d4, int d5, int d6, int d7) // constructor with 7 parametors
{
temp[0] = d1; // assigning constuctor parametors to array
temp[1] = d2;
temp[2] = d3;
temp[3] = d4;
temp[4] = d5;
temp[5] = d6;
temp[6] = d7;
}
public int lowest() // returning the lowest value of the set of numbers
{
int smallest = 150;
for (int c = 0; c < 7; c++)
{
if ( temp[c] < smallest)
{
smallest = temp[c];
}
}
return smallest;
现在我的问题是不要做作业。但是要找到最高温度和平均值的问题。我会做另一个带有 intiatiilzing 的 for 循环,int highest = -1;
然后做一些接近我为最小做的事情吗?