int s_max = 0;
for (int i = 0; i < ar.Length; i++)
{
for (int j = 0; j <ar.Length; j++)
{
if (ar[j] > ar[i])
{
int temp = ar[i];
ar[i] = ar[j];
ar[j] = temp;
}
}
}
if (ar.Length >= 2)
{
s_max= ar[ar.Length - 2];
}
另一种方法
for (int i = 1; i < ar.Length; i++)
{
if (ar[i] > maxnumber)
{
s_max = maxnumber;
maxnumber = ar[i];
}
else
{
if (ar[i] > s_max)
s_max = ar[i];
}
}