tnjk.net
当前位置:首页 >> jAvA编程求数组的平均数 >>

jAvA编程求数组的平均数

public class aveage {public static void main(String[] args) {int[] arrary1 = { 12,4,54,6,78,98,48,787,456 };double x = ave(arrary1);System.out.println("平均数为" + x);}static double ave(int[] a) {int sum = 0;for (int i = 0; i <...

public static void main(String[] args) { int[] a={8,7,1,6,484,54,8};//定义数组 int sum = 0; for (int i : a) { sum+=i;//数组中所有元素总和 } System.out.println("平均数:"+sum/a.length); //最大值方法一 Arrays.sort(a);//数组升序排...

import java.util.Scanner; public class Method { public static void main(String[] args) { System.out.println("请输入10个double类型的数,并以空格隔开:"); double array[]=new double[10]; Scanner scanner=new Scanner(System.in); for(...

这个挺简单吧, for循环外面定义一个变量 循环数组 循环里面累加。 得到数组之和,然后除以数组长度就OK了

public class TestArray {public static void main(String[] args) {int[] nums = {1,2,3,4,5,6};System.out.print("数据为:");for (int i : nums) {System.out.print(i+" ");}System.out.println();//最大值int max = nums[0];for(int i=0;i

首先你这段代码求的是五个数的和而不是平均值package tuxing;这句是打包语句,public class lingxing 这是声明一个公有的类public static void main(String[] args)这是主函数,Java程序运行的入口int a[]={2,4,5,7,5},i,s;这里声明了一个int型...

//求最孝最大、平均、和 public void test(int[] par) { int min=par[0],max=par[0],sum=0,ave=0; for(int i=0;ipar[i]) min = par[i]; if(max

int[] a = {13,46,41,11,20,3,6,41,89,65,24,11}; //数组double sum = 0; //所有元素和double average = 0; //平均值double phase = 0;int b = 0;for (int i = 0; i < a.length; i++) { sum += a[i];}average = sum / a.length;System.out.print...

这些简单的题应该自己多动手写写!! public class ArrayAverage{ /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] a = {1, 2, 3, 4, 5, 6}; double[] b = {6.0, 4.4, 1.9, 2.9, 3.4,...

public class MaxMin { public static void main(String[] args) { Integer[] inte = {12,23,54,75,86}; int max = inte[0]; int min = inte[0]; int average = 0; int sum = 0; for(int i=0;i

网站首页 | 网站地图
All rights reserved Powered by www.tnjk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com