java编程利:用随即函数产生10以内实数20个给数组x赋值,输出数组,求所有元素的平均值 5
展开全部
import java.util.Arrays;
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r=new Random(System.currentTimeMillis());
double a[]=new double[20];
double sum=0.0;
for(int i=0;i<20;i++){
a[i]=r.nextDouble()*10;
sum+=a[i];
}
System.out.println("20个实数为:");
System.out.println(Arrays.toString(a));
System.out.println("均值:"+(sum/20));
}
}
========
20个实数为:
[7.873732321628292, 3.2080138730063545, 6.563220667365596, 3.3113843037545756, 9.751653656732236, 6.454675427992987, 9.05688367016841, 9.782233662567968, 0.05682283565659696, 1.0551253961088558, 4.99457873450356, 3.6028464985777395, 4.061315184413089, 8.094474750937326, 5.186065403355066, 7.527783974190005, 9.38319584928365, 0.5459700122265687, 3.86496645065895, 0.9194797612369576]
均值:5.26472112171824
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r=new Random(System.currentTimeMillis());
double a[]=new double[20];
double sum=0.0;
for(int i=0;i<20;i++){
a[i]=r.nextDouble()*10;
sum+=a[i];
}
System.out.println("20个实数为:");
System.out.println(Arrays.toString(a));
System.out.println("均值:"+(sum/20));
}
}
========
20个实数为:
[7.873732321628292, 3.2080138730063545, 6.563220667365596, 3.3113843037545756, 9.751653656732236, 6.454675427992987, 9.05688367016841, 9.782233662567968, 0.05682283565659696, 1.0551253961088558, 4.99457873450356, 3.6028464985777395, 4.061315184413089, 8.094474750937326, 5.186065403355066, 7.527783974190005, 9.38319584928365, 0.5459700122265687, 3.86496645065895, 0.9194797612369576]
均值:5.26472112171824
展开全部
import java.util.Arrays;
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r=new Random(System.currentTimeMillis());
double a[]=new double[20];
double sum=0.0;
for(int i=0;i<20;i++){
a[i]=r.nextDouble()*10;
sum+=a[i];
}
System.out.println("20个实数为:");
System.out.println(Arrays.toString(a));
System.out.println("均值:"+(sum/20));
}
}
========
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r=new Random(System.currentTimeMillis());
double a[]=new double[20];
double sum=0.0;
for(int i=0;i<20;i++){
a[i]=r.nextDouble()*10;
sum+=a[i];
}
System.out.println("20个实数为:");
System.out.println(Arrays.toString(a));
System.out.println("均值:"+(sum/20));
}
}
========
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
5分,你就想求到?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询