带参数的方法实例

第一个类:

public boolean sear(int start,int end,String name);

boolean find=false;

//在指定的数组区间中查找姓名

  for(int i=start-1;i<end;i++){

    if(names[i].equals(name)){

    find=true;

    break;

  }

}

  return find;

}


测试类:

System.out.print(" 请输入开始查找的位置:");

int s=input.nextInt();

System.out.print("请输入结束查找的位置:");

int e=input.nextInt();

System.out.print("请输入查找的姓名:");

String name=input.next|();

System.out.println(" ***查找的结果***");

  if(st.sear(s,e,name)){

    System.out.println("找到了!!");

  }else{

    System.out.println("没找到学生!!");

}

原文地址:https://www.cnblogs.com/wnwn/p/9804157.html