java應用數組求均勻值,最年夜值,最小值。本站提示廣大學習愛好者:(java應用數組求均勻值,最年夜值,最小值)文章只能為提供參考,不一定能成為您想要的結果。以下是java應用數組求均勻值,最年夜值,最小值正文
(測試類)
package com.badu;
public class Tste {
public static void main(String[] args) {
Class5 sa=new Class5("周阿郎",3,2,24);
Class5 [] a=new Class5[5];
a[0]=new Class5("聲張",2,4,34);
a [1]=new Class5("劉禅",3,2,24);
a[2]=new Class5("張燕",4,23,78);
a [3]=new Class5("周少博",32,23,99);
a [4]=new Class5("張旭",24,13,100);
System.out.println(sa.toString());
double [] w={a[0].getSJava(),a[1].getSJava(),a[2].getSJava(),a[3].getSJava(),a[4].getSJava()};
int s=0;
double max=w[2];
double min=w[0];
for(int i=0;i<5;i++){
s+=w[i]/5;
if(max<w[0]){
max=w[2];
}
if(min>w[0]){
min=w[0];
}
}
System.out.println("java成就的均勻值為"+s+",最小值為"+min+",最年夜值為"+max);
}
}
(一)
package com.badu;
public class Class5 {
private String name;
private int age;
private int sno;
private int sJava;
public Class5(String a,int w,int g,int l){
name=a;
age=w;
sno=g;
sJava=l;
}public Class5(int b){
age=b;
}public Class5(int c,int d){
sno=c;
sJava=d;
}
public Class5(){}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public int getNo(){
return sno;
}
public int getSJava(){
return sJava;
}
public String toString (){
String s="我叫"+name+",我本年"+age+"歲"+"我的java成就是"+sJava;
return s;
}
public static void main(String[] args) {
}
}