qq_朱与墨的晴霜_0
2018-08-22 19:04
string[] name = { "吴松", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何坤", "关欣" };
int[] score = { 89, 90, 98, 56, 60, 91, 93, 85 };
int max = 0, j = 0;
for (int x = 0; x < score.Length; x++)
{
if (max < score[x])
{ //问题在这里if下面加不加这个 {}为什么有很大的区别
max = score[x];
j = x;
}
}
Console.WriteLine("分数最高的是:" + name[j] + "," + "分数是:" + max);
如果if下不加{},“j=x;”这行代码,每次循环都会执行;
加上{},"j=x;"这行代码,只有满足if条件时才执行。
从题意来讲,应该加上{}。
string[] name = { "吴松", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何坤", "关欣" };
int[] score = { 89, 90, 98, 56, 60, 91, 93, 85 };
int max = 0, j = 0;
for (int x = 0; x < score.Length; x++)
{
if (max < score[x])
max = score[x]; //这个是没加的
j = x;
}
Console.WriteLine("分数最高的是:" + name[j] + "," + "分数是:" + max);
C#开发轻松入门
254123 学习 · 1459 问题
相似问题
回答 2
回答 4