从键盘输入10个数,输出这些数中大于其平均值的数,用java编写
2个回答
展开全部
public class T {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double sum = 0;
double s = 0;
System.out.println("请输入10个数:");
int[] a = new int[10];
for (int i = 0; i < a.length; i++) {
a[i] = scanner.nextInt();
sum += a[i];
}
s = sum / a.length;
System.out.println("大于平均值的值如下:");
for (int i = 0; i < a.length; i++) {
if (a[i]>s) {
System.out.print(a[i]+" ");
}
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double sum = 0;
double s = 0;
System.out.println("请输入10个数:");
int[] a = new int[10];
for (int i = 0; i < a.length; i++) {
a[i] = scanner.nextInt();
sum += a[i];
}
s = sum / a.length;
System.out.println("大于平均值的值如下:");
for (int i = 0; i < a.length; i++) {
if (a[i]>s) {
System.out.print(a[i]+" ");
}
}
}
}
展开全部
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int num[] = new int[10];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
num[i] = sc.nextInt(); }
double avg;
long sum = 0;
for (int i = 0; i < num.length; i++) {
sum = sum + num[i];
}
avg = sum / 10;
for (int i = 0; i < num.length; i++) {
if (num[i] > avg)
System.err.println("大于平均数的值为:"+num[i]);
}
}
}
public class Test {
public static void main(String[] args) {
int num[] = new int[10];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
num[i] = sc.nextInt(); }
double avg;
long sum = 0;
for (int i = 0; i < num.length; i++) {
sum = sum + num[i];
}
avg = sum / 10;
for (int i = 0; i < num.length; i++) {
if (num[i] > avg)
System.err.println("大于平均数的值为:"+num[i]);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询