java 错误问题 我是新手 高手指点吧 在线等
发布网友
发布时间:2024-10-08 08:39
我来回答
共3个回答
热心网友
时间:2024-11-07 21:08
给你一个正确的:
public class Test1 {
public static void main(String[] args) {
int max, min, sum;
float ave;
int a[] = new int[10];
max = a[0];
min = a[0];
sum = 0;
ave = 0;
for (int i = 0; i < 10; i++) {
a[i] = Integer.parseInt(args[i]);
if (max < a[i])
max = a[i];
if (min > a[i])
min = a[i];
sum = sum + a[i];
}
ave = sum / 10;
System.out.println("the max is " + max);
System.out.println("the min is " + min);
System.out.println("sum is " + sum);
System.out.println("ave is " + ave);
}
}
热心网友
时间:2024-11-07 21:08
1)
i 没有声明
for(int i=1;i<10;i++)
2)
ary[i]=Integer.parseInt(args[i]);
ary[i]应该是a[i]吧。。。
3)
max min sum. class名字不应该有空白
你的class名字有问题,要改成一个单词的样子,譬如MaxMinAvgSum
class名字第一个大写,好的编程风格让别人也容易读懂你的代码
public class MaxMinAvgSum {
public static void main(String[] args) {
int max, min, sum;
float ave;
int a[] = new int[10];
max = a[0];
min = a[0];
sum = 0;
ave = 0;
for (int i = 1; i < 10; i++) {
a[i] = Integer.parseInt(args[i]);
if (max < a[i])
max = a[i];
if (min > a[i])
min = a[i];
sum = max + a[i];
ave = max / 10;
}
System.out.println("the max is " + max);
System.out.println("the min is " + min);
System.out.println("sum is " + sum);
System.out.println("ave is " + ave);
}
}
热心网友
时间:2024-11-07 21:09
类名用得太不好了,建议多看看书上的程序