tzkr.net
当前位置:首页 >> jAvA求平均数代码 >>

jAvA求平均数代码

你想求什么的平均值?abc的平均值 sum?sum=(a+b+c)/3; system.out.println("a+b+c的平均值是:"+sum);

public class Average{ public static void main(String[] args){//自己定义要求的数 double[] nums = {1, 2.5, 5}; System.out.println("平均数为:" + average(nums)); } public static double average(double[] nums){ double num=0.0; for(int i=0; i<nums.length; i++){ num+=nums[i]; } return num/nums.length; } }

public double getaverage(int[] numbers){int count=0; //存和int times=0;//存大于100 小于0的数出现的次数for(int a:numbers){if(a>100||a<0){times++;}else{count+=a;}system.out.println("不作为统计的数字有"+times+“个”);return count/(int.size()-times)d;}}

num={4,3,6,8,7,1,0,9,5,2};double sum=0;都是用循环,求均值for(int i=0:i<num.size();i++){ sum+= num[i];}sum/num.size()为均值 求最大值double max=sum[0];for(int i=0:i<num.size();i++){ if(max<num[i]) max=num[i];}max为最大值

import java.util.Scanner;//这里要导入包 public class ArithmeticDemo { public static void main(String[] args){//是void,不是woid Scanner in=new Scanner(System.in); int i=in.nextInt(); int j=in.nextInt(); int k=in.nextInt(); System.out.println("平均值");//这里l写成大写的i了 System.out.println("(i+j+k)/3="+(i+j+k)/3);//这里l写成大写的i了 } }

import java.util.*;public class NumOption { public static void main(String[] args) { int sum = 0; int i = 0; int count= 0; Scanner sc = new Scanner(System.in); System.out.println("请输入整数,以0结尾"); do { System.out.print("请输入数字:"

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 < a.length; i++) { sum +=

你运行下我的把 你的好多错误 根据你的给你改的class Student{ public static void main(String[]args){ float[] score={89.0f,100.0f,67,88,90,57,88,90,100,90 }; Student s=new Student(); float avg=s.average(score); System.out.print(avg); } public

import java.util.scanner;public class mydao { public static void main(string args[]){ scanner sc=new scanner(system.in); system.out.println("请输入第1个数:"); int a=sc.nextint(); system.out.println("请输入第2个数:"); int b=sc.nextint(

package test;import java.util.List;public interface Average{ public double getAverage(List&lt;Double&gt; list);}package test;import java.util.List;public class First implements Average { public double getAverage(List&lt;Double&gt; list) { double sum = 0;

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