例题:public class Users {
String a[]={“zhangsan” ,“lisi”,“wangwu”
};
public void findName(int star,int end,String name){
boolean f=false;
for(int i=star;i<end;i++){
if(name.equals(a[i])){
f=true;
break;
}
}
if(f){
System.out.println("查有此人");
}else{
System.out.println("查无此人");
}
}
public void jiSuan(int a[]){
double avg,sum=0,max;
max=a[1];
for(int i=0;i<a.length;i++){
if(a[i]>max){
max=a[i];
}
}
for(int i=0;i<a.length;i++){
sum+=a[i];
}
avg=sum/a.length;
System.out.println(“最大值是”+max);
System.out.println(“平均值是”+avg);
}
public static void main(String[] args) {
Users u=new Users();
u.findName(0,3,“lisi”);
int c[]={1,2,3,4,5};
u.jiSuan©;
}
}