3个回答
展开全部
import java.util.Arrays;
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r = new Random();
int n = 10;
int[] num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = r.nextInt(10);
}
System.out.println("num : " + Arrays.toString(num));
System.out.println("sum : " + sum(num));
System.out.println("avg : " + avg(num, n));
}
public static int sum(int[] num) {
int sum = 0;
for (int n : num) {
sum += n;
}
return sum;
}
public static int avg(int[] num, int n) {
int sum = sum(num);
int avg = sum / n;
return avg;
}
}
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r = new Random();
int n = 10;
int[] num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = r.nextInt(10);
}
System.out.println("num : " + Arrays.toString(num));
System.out.println("sum : " + sum(num));
System.out.println("avg : " + avg(num, n));
}
public static int sum(int[] num) {
int sum = 0;
for (int n : num) {
sum += n;
}
return sum;
}
public static int avg(int[] num, int n) {
int sum = sum(num);
int avg = sum / n;
return avg;
}
}
展开全部
int arr[] = new int[10];
int sum = 0;
int avg = 0;
for (int i = 0; i < arr.length; i++) {
arr[i] = (int) (Math.random()*10);
sum += arr[i];
}
System.out.println("sum:"+sum);
System.out.println("avg:"+sum/arr.length);
int sum = 0;
int avg = 0;
for (int i = 0; i < arr.length; i++) {
arr[i] = (int) (Math.random()*10);
sum += arr[i];
}
System.out.println("sum:"+sum);
System.out.println("avg:"+sum/arr.length);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
声场数字的范围告知下,大概要那个范围的数字(比如1~10之间)
追问
1到100出随机10个,中间用逗号隔开
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询