慕粉1641286813
2017-02-07 16:07
package 我还是爱你的;
public class hg {
public static void main(String[] args){
int scores[]={61,23,4,74,13,148,20};
int max=scores[0];
int main=scores[6];
double sum=0;
double avg=0;
for(int i=0;i<=scores.length;i++){
if(max<scores[i]){
max=scores[i];
}else if(main>scores[i]){
main=scores[i];
}
sum=sum+scores[i];
}
avg=sum/scores.length;
System.out.println(sum);
System.out.println(avg);
}
}
public class hg {
public static void main(String[] args){
int scores[]={61,23,4,74,13,148,20};
int max=scores[0];
int main=scores[6];
double sum=0; (这里是整数求和 为什么用double 不用int????????)
double avg=0;
for(int i=0;i<=scores.length;i++)
少循环一次
改为 i<scores.length
public static void main(String[] args) {
int scores[] = { 61, 23, 4, 74, 13, 148, 20 };
int max = scores[0],min = scores[0];
double sum = 0;
double avg = 0;
for (int i = 0; i <= scores.length-1; i++) {
if (max < scores[i]) {
max = scores[i];
}
if (min > scores[i]) {
min = scores[i];
}
sum = sum + scores[i];
}
avg = sum / scores.length;
System.out.println(sum);
System.out.println(avg);
System.out.println(max);
System.out.println(min);
}
public static void main(String[] args) {
int scores[] = { 61, 23, 4, 74, 13, 148, 20 };
int max = scores[0];
int main = scores[6];
double sum = 0;
double avg = 0;
for (int i = 0; i <= scores.length-1; i++) {
if (max < scores[i]) {
max = scores[i];
} else if (main > scores[i]) {
main = scores[i];
}
sum = sum + scores[i];
}
avg = sum / scores.length;
System.out.println(sum);
System.out.println(avg);
}
main可以
不要用main吧。。main可以用?
不能等于代码长度
Java入门第一季(IDEA工具)升级版
1165634 学习 · 17587 问题
相似问题